You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: more efficient determination of when to hide primary sidebar (#1609)
* minor refactors suggested by Ruff
* move TOC generation from layout.html to sidebar-primary.html
* replace @lru_cache(None) with plain @cache
* get sidebar TOC length without rendering it
* fixup rebase/stash snafu
* bugfix
Copy file name to clipboardExpand all lines: src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html
+5-16
Original file line number
Diff line number
Diff line change
@@ -6,23 +6,8 @@
6
6
{% endset %}
7
7
{%- extends "basic/layout.html" %}
8
8
{%- import "static/webpack-macros.html" as _webpack with context %}
9
-
{# Metadata and asset linking #}
10
-
{# Create the sidebar links HTML here to re-use in a few places #}
11
-
{# If we have no sidebar links, pop the links component from the sidebar list #}
12
-
{%- set sidebar_nav_html = generate_toctree_html("sidebar",
13
-
show_nav_level=theme_show_nav_level|int,
14
-
maxdepth=theme_navigation_depth|int,
15
-
collapse=theme_collapse_navigation|tobool,
16
-
includehidden=True,
17
-
titles_only=True)
18
-
-%}
19
-
{% if sidebar_nav_html | length == 0 %}
20
-
{% set sidebars = sidebars | reject("in", "sidebar-nav-bs.html") | list %}
21
-
{% endif %}
22
9
{# A flag for whether we include a secondary sidebar based on the page metadata #}
23
-
{% set remove_sidebar_secondary = (meta is defined and meta is not none
24
-
and 'html_theme.sidebar_secondary.remove' in meta)
25
-
or not theme_secondary_sidebar_items %}
10
+
{% set remove_sidebar_secondary = (meta is defined and meta is not none and 'html_theme.sidebar_secondary.remove' in meta) or not theme_secondary_sidebar_items %}
26
11
{%- block css %}
27
12
{# The data-cfasync attribute disables CloudFlare's Rocket loader so that #}
28
13
{# mode/theme are correctly set before the browser renders the page. #}
@@ -96,6 +81,10 @@
96
81
<divclass="bd-container">
97
82
<divclass="bd-container__inner bd-page-width">
98
83
{# Primary sidebar #}
84
+
{# If we have no sidebar TOC, pop the TOC component from the sidebar list #}
85
+
{% if get_sidebar_toctree_length(show_nav_level=theme_show_nav_level|int) == 0 %}
86
+
{% set sidebars = sidebars | reject("in", "sidebar-nav-bs.html") | list %}
87
+
{% endif %}
99
88
<divclass="bd-sidebar-primary bd-sidebar{% if not sidebars %} hide-on-wide{% endif %}">
0 commit comments