Skip to content

fix: leave out the View Source button on pages without a repository URL - #453

Merged
mmcky merged 2 commits into
mainfrom
fix/view-source-none-href
Oct 9, 2026
Merged

mmcky merged 2 commits into
mainfrom
fix/view-source-none-href

Conversation

@mmcky

@mmcky mmcky commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #384

What was wrong

On Sphinx's generated pages (genindex.html, search.html, and domain indices such as sphinx-proof's prf-prf.html) the toolbar's GitHub button rendered as <a href="None">. These pages have no source doctree, so add_to_context sets theme_repository_url to None, and layout.html rendered 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 the sphinx-book-theme.js 404 (#454, fixed in #455).

The change

layout.html now renders the View Source <li> only when theme_repository_url is 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 (marked build) builds tests/sites/base with -W and checks that:

  • no link on any page has an href starting with None (parsed with BeautifulSoup, so it checks what a link checker sees)
  • genindex.html and search.html have no View Source button
  • every other page (index, page1, page2 and all of section1/, notebooks included) has exactly one View Source link, pointing at the site's repository_url

Without the template change the first two checks fail (3 failures) and the third passes. With it all four pass.

Verification

  • Full suite: 220 passed on each of Python 3.12 and 3.13 × Sphinx 7.4.7 and 8.2.3 (sphinx-book-theme 1.1.4, pydata-sphinx-theme 0.15.4, myst-nb 1.4.0).
  • Whole-site diff of tests/sites/base built in the same environment before and after: genindex.html and search.html each lose exactly one line, the <li data-tippy-content="View Source"> with href="None". Every other file is byte-identical, apart from a per-build random cell id in _sources/section1/ntbkmd.ipynb.
  • Real Jupyter Book 1 build (jupyter-book 1.0.4.post1, Sphinx 7.4.7) of the pinned fixtures site, link-checked offline together with fix: stop registering sphinx-book-theme.js, which is never copied #455: before, 17 of 18 pages link to None, prf-prf.html included; after, none do. No build warnings either way.
  • The regression fixtures in tests/test_build/ don't include the toolbar and did not change.
  • pre-commit (black, flake8, whitespace hooks) passes.

Visual snapshots: the toolbar icon goes, the job still passes

A site that sets no repository_url has theme_repository_url = None on every page, not just generated ones, so it rendered href="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: its sphinx.config.html_theme_options replaces the options Jupyter Book builds from repository:, 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 visual job still passes. The icon was the last toolbar item, so nothing shifts, and the missing icon stays within the snapshot tolerances (toolbar.png allows 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:

  1. Leave the baselines as they are. Nothing fails today.
  2. Regenerate them with /update-snapshots on this PR so they match what the fixtures site now renders.
  3. Add repository_url to html_theme_options in the fixtures repo's _config.yml and bump FIXTURES_SHA, so the icon comes back and the fixtures look more like the lecture sites, which all set it. repository_url is 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

Merge note

#455 also adds a ### Fixed section under [Unreleased] in CHANGELOG.md, so whichever merges second will need a one-line conflict resolution there.

🤖 Generated with Claude Code

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]>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 01:18
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

@github-actions
github-actions Bot temporarily deployed to pull request October 9, 2026 01:19 Inactive
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@4176e26). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #453   +/-   ##
=======================================
  Coverage        ?   56.30%           
=======================================
  Files           ?        2           
  Lines           ?      547           
  Branches        ?        0           
=======================================
  Hits            ?      308           
  Misses          ?      239           
  Partials        ?        0           
Flag Coverage Δ
pytests 56.30% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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> in layout.html with {%- if theme_repository_url %} so it is only rendered when a repository URL exists.
  • Add tests/test_view_source.py, a build-marked end-to-end test verifying no href starts with None, that generated pages have no button, and that source pages keep exactly one button pointing at the configured repository_url.
  • Add a ### Fixed CHANGELOG 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]>
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Visual Regression Test Results

passed  102 passed
flaky  1 flaky
skipped  3 skipped

Details

stats  106 tests across 1 suite
duration  4 minutes, 32 seconds
commit  1d9b39a

Flaky tests

desktop-chrome › theme.spec.ts › Visual Regression Tests › exercises - full page screenshot

Skipped tests

desktop-chrome › theme.spec.ts › Visual Regression Tests › prob-matrix - full page screenshot
mobile-chrome › theme.spec.ts › Visual Regression Tests › prob-matrix - full page screenshot
mobile-chrome › theme.spec.ts › Theme Features › f-string interpolation styling

@github-actions
github-actions Bot temporarily deployed to pull request October 9, 2026 01:24 Inactive
@mmcky
mmcky merged commit 2d9bbe5 into main Oct 9, 2026
12 checks passed
@mmcky
mmcky deleted the fix/view-source-none-href branch October 9, 2026 01:54
mmcky added a commit that referenced this pull request Oct 9, 2026
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]>
mmcky added a commit that referenced this pull request Oct 9, 2026
)

* 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>
@mmcky mmcky mentioned this pull request Oct 9, 2026

This branch was previously deployed

1 inactive deployment
pull request — 1d9b39af Deployed Oct 9, 2026 by github-actions[bot]
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.

View Source toolbar button renders href="None" on auto-generated pages (genindex, search, proof index)

2 participants