Repository navigation
fix: leave out the View Source button on pages without a repository URL - #453
Conversation
Sphinx's generated pages (genindex, search, domain indices such as sphinx-proof's prf-prf) have no source doctree, so add_to_context sets theme_repository_url to None and the toolbar rendered <a href="None">. Render the button only when theme_repository_url is set. Pages with a source document keep the button with the same URL as before. Adds tests/test_view_source.py, which builds the base test site and checks that no link points at None, that genindex and search have no View Source button, and that every other page still has it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #453 +/- ##
=======================================
Coverage ? 56.30%
=======================================
Files ? 2
Lines ? 547
Branches ? 0
=======================================
Hits ? 308
Misses ? 239
Partials ? 0
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:
|
There was a problem hiding this comment.
🟢 Approval recommended
The one-line template guard matches the established pattern, is confirmed by __init__.py setting the URL to None on generated pages, and is backed by a convention-following regression test with a correctly placed changelog entry.
0 open findings
What changed in this PR
This PR fixes issue #384, where the toolbar's "View Source" GitHub button rendered as <a href="None"> on Sphinx-generated pages (genindex.html, search.html, and domain indices like sphinx-proof's prf-prf.html). Those pages have no source doctree, so add_to_context in __init__.py sets theme_repository_url to None, and layout.html previously rendered the link unconditionally, producing broken links that link checkers report as missing files. The fix wraps the button in the same {%- if theme_repository_url %} guard already used by the neighboring Download/Launch Notebook buttons, so the button is simply omitted when there is no repository URL. This is "option 1" from the issue; the broader behavioral option (populating the URL on generated pages) is deliberately out of scope.
Changes:
- Guard the "View Source"
<li>inlayout.htmlwith{%- if theme_repository_url %}so it is only rendered when a repository URL exists. - Add
tests/test_view_source.py, abuild-marked end-to-end test verifying no href starts withNone, that generated pages have no button, and that source pages keep exactly one button pointing at the configuredrepository_url. - Add a
### FixedCHANGELOG entry under[Unreleased].
| File | Description |
|---|---|
src/quantecon_book_theme/theme/quantecon_book_theme/layout.html |
Wraps the View Source button in an {%- if theme_repository_url %} guard, matching the surrounding button pattern, to avoid href="None". |
tests/test_view_source.py |
New end-to-end @pytest.mark.build test covering the None-href regression and button presence/absence across page types. |
CHANGELOG.md |
Adds a ### Fixed entry under [Unreleased] documenting the fix (#384). |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
A site that sets no repository_url gets theme_repository_url = None on every page, so it rendered href="None" everywhere and now shows no View Source button at all. The visual-test fixtures site is one of these. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🎭 Visual Regression Test ResultsDetails
Flaky testsdesktop-chrome › theme.spec.ts › Visual Regression Tests › exercises - full page screenshot Skipped testsdesktop-chrome › theme.spec.ts › Visual Regression Tests › prob-matrix - full page screenshot |
Brings in #453. CHANGELOG.md conflicted because both PRs added a ### Fixed section under [Unreleased]; keep both entries in one section, #384's first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
) * test: refresh visual baselines after #453 Starter commit for the snapshot refresh; the regenerated baselines are added by /update-snapshots once #456 is on main. Co-Authored-By: Claude Opus 5.5 <[email protected]> * UPDATE: Regenerate all visual snapshots (39 files) * ci: trigger run on regenerated baselines Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Fixes #384
What was wrong
On Sphinx's generated pages (
genindex.html,search.html, and domain indices such as sphinx-proof'sprf-prf.html) the toolbar's GitHub button rendered as<a href="None">. These pages have no source doctree, soadd_to_contextsetstheme_repository_urltoNone, andlayout.htmlrendered the button unconditionally. A link check of lecture-jax (built from main with 0.22.0 on 2026-10-09) found these as the only missing link targets apart from thesphinx-book-theme.js404 (#454, fixed in #455).The change
layout.htmlnow renders the View Source<li>only whentheme_repository_urlis set, the same{%- if %}guard the Download Notebook and Launch Notebook buttons beside it already use. Generated pages show no button. Every page with a source document keeps it, with the same URL as today.This takes option 1 from #384 only. Option 2 (filling in the repository URL on generated pages so they keep a button) is not done here.
Tests
tests/test_view_source.py(markedbuild) buildstests/sites/basewith-Wand checks that:None(parsed with BeautifulSoup, so it checks what a link checker sees)genindex.htmlandsearch.htmlhave no View Source buttonsection1/, notebooks included) has exactly one View Source link, pointing at the site'srepository_urlWithout the template change the first two checks fail (3 failures) and the third passes. With it all four pass.
Verification
tests/sites/basebuilt in the same environment before and after:genindex.htmlandsearch.htmleach lose exactly one line, the<li data-tippy-content="View Source">withhref="None". Every other file is byte-identical, apart from a per-build random cell id in_sources/section1/ntbkmd.ipynb.None,prf-prf.htmlincluded; after, none do. No build warnings either way.tests/test_build/don't include the toolbar and did not change.Visual snapshots: the toolbar icon goes, the job still passes
A site that sets no
repository_urlhastheme_repository_url = Noneon every page, not just generated ones, so it renderedhref="None"on every page and now shows no View Source button at all. The CHANGELOG entry says this too. The visual-test fixtures site is one of these: itssphinx.config.html_theme_optionsreplaces the options Jupyter Book builds fromrepository:, so no repository URL reaches the theme. In this PR's Netlify preview the fixtures toolbar ends at "Download PDF", with no GitHub icon.The
visualjob still passes. The icon was the last toolbar item, so nothing shifts, and the missing icon stays within the snapshot tolerances (toolbar.pngallows 3% of pixels to differ, full-page shots 1%). The committed baselines therefore still show the icon, and that known difference uses up part of the toolbar's tolerance for later changes. Options, your call:/update-snapshotson this PR so they match what the fixtures site now renders.repository_urltohtml_theme_optionsin the fixtures repo's_config.ymland bumpFIXTURES_SHA, so the icon comes back and the fixtures look more like the lecture sites, which all set it.repository_urlis already in released versions, so this needs no release dance. It may also turn on the changelog's "full history" and commit links.I haven't done any of these.
Left alone
<!-- -->, not a Jinja comment), so Jinja still renders it and generated pages still contain the texthref="None/"inside that comment. It is not a link, and browsers and link checkers ignore it, but a rawgrepof the built HTML will find it.get_github_src_folderfinds the folder byrfindof the repository name in the build path #452 (the View Source URL drops the source folder when it is named like the repository) touches the same lines and is out of scope here.rel="noopener noreferrer"ontarget="_blank"links) also touches this line and is out of scope here.Merge note
#455 also adds a
### Fixedsection under[Unreleased]inCHANGELOG.md, so whichever merges second will need a one-line conflict resolution there.🤖 Generated with Claude Code