Skip to content

FIX secondary sidebar persists even if it is empty #1688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
{%- extends "basic/layout.html" %}
{%- import "static/webpack-macros.html" as _webpack with context %}
{# A flag for whether we include a secondary sidebar based on the page metadata #}
{% 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 %}
{# Note: secondary_sidebar_items is an array set by set_secondary_sidebar_items() in utils.py #}
{% set remove_sidebar_secondary = (meta is defined and meta is not none and 'html_theme.sidebar_secondary.remove' in meta) or secondary_sidebar_items|length == 0 %}
{%- block css %}
{# The data-cfasync attribute disables CloudFlare's Rocket loader so that #}
{# mode/theme are correctly set before the browser renders the page. #}
Expand Down
22 changes: 22 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,11 @@ def test_render_secondary_sidebar_dict(sphinx_build_factory) -> None:
assert not sphinx_build.html_tree("section1/index.html").select("div.sourcelink")
assert sphinx_build.html_tree("section2/index.html").select("div.sourcelink")

# Check that the secondary sidebar is completely removed for section1/index
assert not sphinx_build.html_tree("section1/index.html").select(
"div.bd-sidebar-secondary"
)


def test_render_secondary_sidebar_dict_glob_subdir(sphinx_build_factory) -> None:
"""Test that the secondary sidebar can be built with a dict of templates that globs a subdir."""
Expand Down Expand Up @@ -1173,3 +1178,20 @@ def test_role_main_for_search_highlights(sphinx_build_factory):
"""
sphinx_build = sphinx_build_factory("base").build()
assert sphinx_build.html_tree("index.html").select_one('[role="main"]')


def test_sidebar_secondary_templates_all_empty(sphinx_build_factory) -> None:
"""Test that the secondary sidebar is removed if all templates are empty."""
confoverrides = {
"html_theme_options": {
**COMMON_CONF_OVERRIDES,
"secondary_sidebar_items": ["page-toc", "sourcelink"],
},
"html_show_sourcelink": False,
}

# The page-toc component is empty because there is no in-page toc for page1
# The sourcelink component is empty because we disabled it in configuration
# Hence the secondary sidebar has all its templates empty and should be removed
sphinx_build = sphinx_build_factory("base", confoverrides=confoverrides).build()
assert not sphinx_build.html_tree("page1.html").select("div.bd-sidebar-secondary")