fix(docs): stop the version banner showing on the stable docs - #142
Conversation
The version switcher marked a synthetic `{"version": "stable"}` entry as
preferred. pydata-sphinx-theme gates the warning banner on
const i = t(o) && t(s); // t = /^[v\d]/ + semver regex
if (i && n(o, s, "=")) return; // suppress banner
where `s` is the preferred entry's version. `t("stable")` is false, so the
suppression branch was unreachable and every page rendered
"This is documentation for version 0.5.0. [Switch to stable version]" —
including /stable/ itself, whose button linked back to the current page.
Drop the pseudo-version entry: the newest release is now the preferred one
and is served from the /stable/ alias, named "0.5.0 (stable)". Older
releases keep their own versioned URL, so they correctly report "an old
version (X.Y.Z)" instead of a bare "version X.Y.Z".
Also in the release workflow:
- Read switcher.json from the gh-pages worktree instead of curl-ing the
published site, which is served through a CDN cache and could hand the
build a stale copy.
- Only copy to stable/ when the tag is the newest release, so a backport
tag cannot demote a newer one.
- Add a workflow_dispatch job that rebuilds switcher.json from the version
folders present on gh-pages, to fix the live site without cutting a
release. The folder list is used rather than git tags because tags
predating the versioned docs have no folder to link to.
Closes tee-ar-ex#141
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #142 +/- ##
==========================================
+ Coverage 86.46% 86.86% +0.40%
==========================================
Files 13 14 +1
Lines 2881 2970 +89
==========================================
+ Hits 2491 2580 +89
Misses 390 390
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thank for doing this! One question:
How/where do I do that? I am not familiar with localStorage. |
|
Oh, I think I understand. This is probably something I need to clear in the browser cache locally. Will test on an incognito window or different browser once merged. For now, merging! Thanks! |
|
Oh - darn. I didn't notice that this was against the master branch. I recently switched to use |
|
Thank you for this, I need to update to main also, I think we should tag and warn all fork |
Closes #141.
Root cause
Not gh-pages, not the deploy workflow — one field in
switcher.json.tools/update_switcher.pyappended a synthetic entry and always movedpreferredonto it:{"name": "stable", "version": "stable", "url": ".../stable/", "preferred": true}But pydata-sphinx-theme gates the version-warning banner on a semver parse of the preferred entry's
versionfield:"stable"fails the/^[v\d]/test, so the suppression branch could never run and every page fell through to the finalelse. That is the banner in the issue — rendered on/stable/itself, with a "Switch to stable version" button linking back to the page you are already on.Fix
Drop the pseudo-version entry. Following the numpy/scipy/pandas convention, the newest release is the stable entry and is served from the
/stable/alias:[ {"name": "dev", "version": "dev", "url": ".../dev/"}, {"name": "0.5.0 (stable)", "version": "0.5.0", "url": ".../stable/", "preferred": true}, {"name": "0.4.0", "version": "0.4.0", "url": ".../0.4.0/"}, {"name": "0.3", "version": "0.3", "url": ".../0.3/"} ]This is a pure data fix. Every deployed page fetches
switcher.jsonfrom the site root at runtime (the URL is hardcoded absolute inconf.py), so correcting the file fixes/stable/,/0.4.0/,/0.3/and/dev/retroactively, with no doc rebuild.Verification
Ran the theme's own regex and predicate, copied verbatim from the deployed bundle, against both the current and the proposed file:
/stable/banner: "version 0.5.0"← the bug/0.5.0/banner: "version 0.5.0"/0.4.0/banner: "version 0.4.0"banner: "an old version (0.4.0)"/0.3/banner: "version 0.3"banner: "an old version (0.3)"/dev/banner: "an unstable development version"The old-release banners were wrong for the same reason: with an unparseable preferred version the
<comparison could not run either, so they reported a bareversion X.Y.Zinstead ofan old version (X.Y.Z).Changes
tools/update_switcher.py— rewritten aroundbuild_switcher(). The newest release getspreferred, the" (stable)"name suffix and the/stable/URL; older releases keep their versioned URL. Newparse_version()andis_latest()helpers, and a--rebuildmode. Stdlib only, since the deploy job runs this with the bare runner Python and installs no dependencies..github/workflows/docbuild.ymlswitcher.jsonfrom the gh-pages worktree instead ofcurl-ing the published site. Pages serves that through a CDN cache, so two tags pushed in quick succession could be built from a stale copy and silently drop an entry.stable/when the tag is the newest release, so a backport tag such as0.4.1published after0.5.0still gets its own folder but cannot demote stable.workflow_dispatchrebuild-switcherjob, so the live site can be fixed without cutting a release. It derives the version list from the folders actually published on gh-pages rather than fromgit tag -l, because tags0.0.1–0.2.9predate the versioned docs and have no folder to link to.docs/source/conf.py—version_matchcollapsed to"dev" if "dev" in version else version. Behaviour is unchanged; the previous form was only accidentally correct.trx/tests/test_update_switcher.py— new.update_switcher.pywas untested and is the thing that broke. 22 tests, including a named regression test asserting no entry ever carries"version": "stable", plus coverage of the backport guard and--rebuildidempotency.After merge
Run the workflow manually (Actions → Documentation build → Run workflow) to rewrite
switcher.jsonon gh-pages and fix the live banner. ClearlocalStorage.pst_banner_prefbefore checking — the theme remembers dismissals for 14 days and will otherwise mask the result.