{# Start the sidebar from the deepest captioned section the page lives under: - user-guide/* (any version, including the index itself) always anchors at user-guide/index (depth 1) and nests each version's own captioned groups inside that version's accordion (see user_guide_sidebar_html in conf.py), so the same version-accordion tree stays visible and stable across every User Guide page — only the "current" highlighting and which accordion is expanded change. - contributor-guide/* lives under contributor-guide/index.md, so start at depth 1 - root and orphan pages (search, genindex) fall back to the global toctree (depth 0). user_guide_versioned additionally requires a real depth-1 ancestor to exist, so orphan pages under user-guide/ (not reachable from any toctree) fall through to the depth-0 global fallback below instead of crashing generate_toctree_html. #} {% set user_guide_versioned = pagename.startswith("user-guide/") and not suppress_sidebar_toctree(startdepth=1, includehidden=True) %} {% if user_guide_versioned %} {% elif not suppress_sidebar_toctree(startdepth=1, includehidden=True) %} {% set sidebar_startdepth = 1 %} {% else %} {% set sidebar_startdepth = 0 %} {% endif %}