Skip to content

Native version switcher and latest-release links, on top of the injected switcher - #36

Merged
garth-wells merged 6 commits into
dokken/version-switcherfrom
version-switcher
Oct 24, 2026
Merged

garth-wells merged 6 commits into
dokken/version-switcherfrom
version-switcher

Conversation

@garth-wells

@garth-wells garth-wells commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Stacked on #35. This PR targets #35's branch and changes only what's needed to combine the two. When #35 merges, GitHub retargets this PR to main.

Together they put exactly one version dropdown on every page:

Pages Dropdown
New builds, made with the switcher configured (FEniCS/dolfinx#4681, FEniCS/basix#1108, FEniCS/ffcx#931, FEniCS/ufl#542) pydata-sphinx-theme's own
Releases already published with pydata-sphinx-theme: DOLFINx v0.11.0 and v0.11.0.post0, Basix v0.11.0, FFCx v0.11.0, UFL 2025.3.0–2026.2.0 pydata-sphinx-theme's own, enabled at deploy time by this PR
Releases with other themes (Read the Docs, Alabaster, "nature"), and Doxygen pages #35's injected switcher

This PR also adds a single, unversioned link per package that always opens the latest release.

Changes on top of #35

make_switcher.py runs in website.yml after #35's injection and check, and writes only below _html. It:

  • Writes the native version lists: dolfinx/switcher-python.json, dolfinx/switcher-cpp.json, basix/switcher-python.json, ffcx/switcher.json, ufl/switcher.json. They are built from the versions.json files that make_versions.py writes earlier in the same deploy, so both switchers list the same releases and agree on which is stable.
  • Writes redirects to the latest release: /dolfinx/, /dolfinx/python/, /dolfinx/cpp/, /basix/, /basix/python/, /basix/cpp/, /ffcx/, /ufl/. The README gains a section with these links.
  • Enables the native switcher on the releases already published with pydata-sphinx-theme. These builds already contain the theme's switcher code. It adds the switcher options and markup and drops the version from the title. It also removes Add a version switcher to all docs pages #35's injected switcher from those pages, so they have one switcher, not two. On the stable release the version banner is off, because these older theme versions misdetect .postN releases as old.

Changes to #35's files:

  • inject_switcher.py skips pages that already have the native switcher.
  • make_versions.py and version-switcher.js list one entry per release, without .postN (e.g. v0.10.0), as the native lists do. The injected switcher matches .postN builds to their release and opens the release's newest build.

#35's check (inject_switcher.py --verify) runs unchanged, before make_switcher.py changes anything.

Testing

I ran the website.yml steps on a full copy of the published site, with the main folders replaced by docs built locally from the four package PRs, and checked every page with a script. I also checked a local preview in a browser.

This repository's CI only runs on PRs to main, so it will run here once #35 merges.

AI assistance: I used Claude Code (Claude Opus 5.5) to draft parts of this PR. I reviewed, edited, tested, and take responsibility for the final contribution.

🤖 Generated with Claude Code

@jorgensd

Copy link
Copy Markdown
Member

Can you comment on how this differs from: #35

@garth-wells

Copy link
Copy Markdown
Member Author

Can you comment on how this differs from: #35

I didn't see #35 at first. The difference is that this PR used the native Sphinx versioning drop down.

@jorgensd

Copy link
Copy Markdown
Member

Will we get older versions in the dropdown, ie everything pre sphinx pydata theme?

@garth-wells
garth-wells force-pushed the version-switcher branch 2 times, most recently from 753db8a to 61c8fb0 Compare October 24, 2026 20:39
@garth-wells
garth-wells changed the base branch from main to dokken/version-switcher October 24, 2026 20:39
@garth-wells garth-wells changed the title Generate documentation version switcher lists and latest-release redirects Native version switcher and latest-release links, on top of the injected switcher Oct 24, 2026
@garth-wells

Copy link
Copy Markdown
Member Author

Will we get older versions in the dropdown, ie everything pre sphinx pydata theme?

No it didn't, so I've stacked this PR on #35 so older releases get the #35 dropdown and the new releases get the native Sphinx dropdown.

garth-wells and others added 5 commits October 24, 2026 21:52
make_switcher.py writes a pydata-sphinx-theme version switcher JSON per
documentation set from the published version folders, and redirect pages
so that e.g. /dolfinx/python/ always opens the latest release. Only the
newest .postN of each release is listed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Releases built with pydata-sphinx-theme before the switcher was configured
already ship the theme code that renders it. At deploy time, add the
switcher options and markup to those pages and drop the version from the
title, so the latest-release redirects land on a page with the dropdown.

make_switcher.py now writes only into the deploy folder, so patching
published pages never touches the repository checkout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Older pydata-sphinx-theme versions decide whether a page is the stable
version by comparing release numbers, which fails for .postN releases and
showed a "switch to stable version" banner on the stable release itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Entries are named and matched by release (e.g. v0.10.0), and link to the
newest .postN build. All .postN builds of a release highlight its entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- inject_switcher.py skips pages that already have the pydata-sphinx-theme
  version switcher, i.e. builds made with it configured.
- make_switcher.py runs after inject_switcher.py and its check. On releases
  built with pydata-sphinx-theme it enables the native switcher and removes
  the injected one, so every page has exactly one switcher.
- versions.json lists one entry per release, without .postN, matching the
  native lists; the injected switcher matches .postN builds to their
  release and opens its newest build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Read the versions from the versions.json files written by
  make_versions.py instead of rebuilding them, so the release and stable
  rules exist once.
- Share release(), BASE_URL, the injected tag and the directory walker
  with make_versions.py and inject_switcher.py.
- Give each library its subfolders explicitly, rather than relying on the
  order of a table for the library redirect.
- Leave .gitignore unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@garth-wells
garth-wells merged commit 73179a5 into main Oct 24, 2026
2 checks passed
@garth-wells
garth-wells deleted the version-switcher branch October 24, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants