Skip to content

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

Description

@mmcky

Summary

On Sphinx auto-generated pages (genindex.html, search.html, and the proof-domain index prf-prf.html), the "View Source" GitHub button in the toolbar renders as <a href="None" ...>, producing broken links. Regular lecture pages render correctly.

Reproducer

Build any project using this theme that has a repository_url configured and at least one prf:proof directive. Inspect the generated _build/html/genindex.html, _build/html/search.html, and _build/html/prf-prf.html — the toolbar's GitHub icon <a> has href="None".

Caught by lychee link-checker on lecture-python.myst:

```

Errors in genindex.html

  • [ERROR] file:///.../None | Cannot find file: File not found.

Errors in search.html

  • [ERROR] file:///.../None | Cannot find file: File not found.

Errors in prf-prf.html

  • [ERROR] file:///.../None | Cannot find file: File not found.
    ```

Root cause

In `src/quantecon_book_theme/init.py`, `theme_repository_url` is only populated inside the `if doctree and hasattr(app.env, "doc2path"):` branch (lines ~470–472). On auto-generated pages there's no source doctree, so the `else` branches (lines 481 and 487) set `context["theme_repository_url"] = None`.

`src/quantecon_book_theme/theme/quantecon_book_theme/layout.html:399` then interpolates the value unguarded:

```jinja

  • ...
  • \`\`\`

    Jinja stringifies Python `None` to the literal `"None"`, producing `href="None"`.

    Suggested fix

    Two reasonable options (either or both):

    1. Guard the template — match the existing `{%- if notebook_path %}` / `{%- if theme_nb_repository_url %}` pattern used a few lines above:
      ```jinja
      {%- if theme_repository_url %}
    2. ...
    3. {%- endif %} \`\`\`
    4. Populate the variable unconditionally in `init.py` — read `repository_url` from `config_theme` regardless of whether a doctree is present, so the global "View Source" link works on auto-generated pages too.

    Option 1 alone removes the broken link; option 1 + 2 also keeps the button visible on auto-generated pages.

    Version

    Reproduced on `main` (v0.20.3); also affects v0.20.2 (deployed on lecture-python.myst).

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      No labels
      No labels

      Type

      No type

      Projects

      No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions