Skip to content
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

FIX empty primary sidebar showing up #1682

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 1 addition & 8 deletions src/pydata_sphinx_theme/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,7 @@ def suppress_sidebar_toctree(startdepth: int = 1, **kwargs):
)
if ancestorname is None:
return True # suppress
if kwargs.get("includehidden", False):
# if ancestor is found and `includehidden=True` we're guaranteed there's a
# TocTree to be shown, so don't suppress
return False

# we've found an ancestor page, but `includehidden=False` so we can't be sure if
# there's a TocTree fragment that should be shown on this page; unfortunately we
# must resolve the whole TOC subtree to find out

toctree = get_nonroot_toctree(
app, pagename, ancestorname, toctree_obj, **kwargs
)
Expand Down
18 changes: 18 additions & 0 deletions tests/sites/test_primary_sidebar_toc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Test conf file."""

# -- Project information -----------------------------------------------------

project = "PyData Tests"
copyright = "2020, Pydata community"
author = "Pydata community"

root_doc = "index"

# -- General configuration ---------------------------------------------------

html_theme = "pydata_sphinx_theme"

html_copy_source = True
html_sourcelink_suffix = ""

html_theme_options = {"navigation_with_keys": False}
7 changes: 7 additions & 0 deletions tests/sites/test_primary_sidebar_toc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test-primary-sidebar-toc
========================

.. toctree::

page
sec/index
5 changes: 5 additions & 0 deletions tests/sites/test_primary_sidebar_toc/page.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
============
Page at Root
============

Some text.
10 changes: 10 additions & 0 deletions tests/sites/test_primary_sidebar_toc/sec/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
===============
Section at Root
===============

Some text.

.. toctree::
:hidden:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test case is at all dependent on the change made in this PR, but it seems like a nice test case to have in the test suite. 😄


subpage
15 changes: 15 additions & 0 deletions tests/sites/test_primary_sidebar_toc/sec/subpage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
===============
Page in Section
===============

Some text.

Subsection
==========

Some text.

Subsubsection
-------------

Some text.
20 changes: 20 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,3 +1142,23 @@ 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_primary_sidebar_hidden_when_empty(sphinx_build_factory) -> None:
"""Test that the primary sidebar does not show up if it is empty."""
sphinx_build = sphinx_build_factory("test_primary_sidebar_toc").build()
sidebar_primary = sphinx_build.html_tree("page.html").select(
"div.bd-sidebar-primary"
)[0]
assert "hide-on-wide" in sidebar_primary.attrs["class"]


def test_primary_sidebar_exist_when_hidden_toctree(sphinx_build_factory) -> None:
"""Test that the primary sidebar shows up if there are hidden toctrees."""
sphinx_build = sphinx_build_factory("test_primary_sidebar_toc").build()
for page in ("sec/index.html", "sec/subpage.html"):
sidebar_primary = sphinx_build.html_tree(page).select("div.bd-sidebar-primary")[
0
]
assert "hide-on-wide" not in sidebar_primary.attrs["class"]
assert "Page in Section" in str(sidebar_primary)
Loading