Skip to content

Commit 3c8b530

Browse files
timsaucerclaude
andcommitted
docs: render sidebar nav on landing page
The default pydata-sphinx-theme sidebar-nav-bs starts at the current top-level section, so the root index — which has no parent section — ends up with an empty sidebar. The theme's layout also explicitly filters sidebar-nav-bs out of the sidebar list when suppress_sidebar_ toctree() returns true (which it does for root pages), so simply overriding sidebar-nav-bs.html in templates doesn't help. Add a sidebar-globaltoc.html template that calls Sphinx's toctree() global directly to render the full document tree, and wire it through html_sidebars under a name the theme's suppress filter doesn't strip. Landing page now shows User Guide / Contributor Guide / API Reference in the sidebar with the current section expanded on inner pages. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 41030ef commit 3c8b530

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{# Overrides pydata-sphinx-theme's sidebar-nav-bs to render the global
2+
document toctree on every page (including the landing page). The
3+
stock template's generate_toctree_html starts at the current
4+
section, which leaves the root index with no sidebar at all. Using
5+
the toctree() Jinja global instead always shows the top-level
6+
structure, with the current section expanded and highlighted. #}
7+
<nav class="bd-docs-nav bd-links" aria-label="{{ _('Section Navigation') }}">
8+
<p class="bd-links__title" role="heading" aria-level="1">{{ _("Section Navigation") }}</p>
9+
<div class="bd-toc-item navbar-nav">
10+
{{ toctree(maxdepth=theme_navigation_depth | int,
11+
collapse=theme_collapse_navigation | tobool,
12+
includehidden=True,
13+
titles_only=True) }}
14+
</div>
15+
</nav>

docs/source/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ def setup(sphinx) -> None:
168168

169169
html_css_files = ["theme_overrides.css"]
170170

171+
html_sidebars = {
172+
"**": ["sidebar-globaltoc"],
173+
}
174+
171175
# tell myst_parser to auto-generate anchor links for headers h1, h2, h3
172176
myst_heading_anchors = 3
173177

0 commit comments

Comments
 (0)