Skip to content

Add a version switcher to all docs pages - #35

Merged
garth-wells merged 2 commits into
mainfrom
dokken/version-switcher
Oct 24, 2026
Merged

garth-wells merged 2 commits into
mainfrom
dokken/version-switcher

Conversation

@jorgensd

Copy link
Copy Markdown
Member

Adds a Read-the-Docs-style version dropdown to every page on docs.fenicsproject.org, including old builds and Doxygen pages, without rebuilding anything.

At deploy time, website.yml now:

  • runs make_versions.py, which writes <project>/versions.json from the version folders (main and tags) and marks the newest release as stable
  • runs inject_switcher.py, which adds one <script> line before </body> in each HTML page
  • runs inject_switcher.py --verify ., which fails the job if any published file differs from the repo by more than that line

Only the Pages artifact is modified; nothing is committed back.

The dropdown opens the same page in the selected version. If that page doesn't exist there, it falls back to the nearest parent page, then to python/ or cpp/. dolfinx Doxygen pages map between cpp/ (v0.1–v0.3) and cpp/doxygen/ (v0.4+). Old releases also show a dismissible "newer release available" banner.

  • No existing URL changes. The only new paths are /_fenics/version-switcher.js, /versions.json and /<project>/versions.json.
  • New versions appear automatically when a project's CI pushes its docs.

Tested on a full copy of the site:

  • Injection and verification take about 10 s.
  • The verify step found 0 differences besides the added line.
  • Headless-browser checks passed across all themes and Doxygen versions.

Follow-up: generate the README/index version list from versions.json and remove mark_old_docs.py.

🤖 Generated with Claude Code

@garth-wells

Copy link
Copy Markdown
Member

Sphinx has a native version switcher. Better to use the native one.

@jorgensd

Copy link
Copy Markdown
Member Author

Will we get older versions from pre pydata sphinx? Ie. 0.6-0.10?

@garth-wells

Copy link
Copy Markdown
Member

I pushed a small cleanup commit (ba70260) to this branch. It doesn't change the injected pages:

  • One project list. PROJECTS is defined once, in make_versions.py, and inject_switcher.py imports it.
  • One directory walker. Injection and --verify now share a walker in inject_switcher.py.
  • Unused --base-url option removed. The workflow never passed it.
  • Each versions.json url now points at a front page that exists. Previously every dolfinx entry and three basix entries linked to a version folder with no index.html. For example, dolfinx/v0.11.0.post0/ is now dolfinx/v0.11.0.post0/python/.
  • Version switching checks its candidate pages in parallel. Previously it checked them one at a time, which could mean 5–10 sequential round trips on a Doxygen page.

I checked it by running the original and new scripts on a full copy of the site. All 15,422 pages came out byte-for-byte identical, and --verify passed on both. The only output change is the url fields.

Some things I left for you to decide:

  • /versions.json (all projects) is published, but nothing reads it.
  • The "Add version switcher" step is duplicated in both workflow jobs.
  • The JS works out the site root from its own URL, but the script is injected with an absolute /_fenics/... path, so that code doesn't currently take effect.
  • The dolfinx Doxygen paths and the "old release" decision could be written into versions.json by make_versions.py instead of being worked out in the JS.

#36 is stacked on this PR. It enables the theme's own version switcher wherever the theme supports it, and this PR's switcher covers the remaining pages.

@garth-wells
garth-wells added this pull request to stack #37 October 24, 2026 20:50
jorgensd and others added 2 commits October 24, 2026 21:52
- Define the project list once, in make_versions.py.
- Use one directory walker in inject_switcher.py.
- Drop the unused --base-url option; point each versions.json url at the
  version front page that exists (python/ for dolfinx), not the folder.
- Check the candidate pages in parallel when switching versions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@garth-wells
garth-wells force-pushed the dokken/version-switcher branch from ba70260 to 843c08a Compare October 24, 2026 20:52
@garth-wells garth-wells added the enhancement New feature or request label Oct 24, 2026
@garth-wells
garth-wells merged commit 73179a5 into main Oct 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants