fix(docs): stop the version banner showing on the stable docs - #142
Open
skoudoro wants to merge 1 commit into
Open
fix(docs): stop the version banner showing on the stable docs#142skoudoro wants to merge 1 commit into
skoudoro wants to merge 1 commit into
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:
|
Member
|
Thank for doing this! One question:
How/where do I do that? I am not familiar with localStorage. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.