pydata / pydata-sphinx-theme

A clean, three-column Sphinx theme with Bootstrap for the PyData community
https://pydata-sphinx-theme.readthedocs.io
BSD 3-Clause "New" or "Revised" License
565 stars 304 forks source link

Removing secondary sidebar via conf and via page-wide metadata are not consistent #1686

Closed Charlie-XIAO closed 5 months ago

Charlie-XIAO commented 6 months ago

From the documentation there are two ways to remove the secondary sidebar from a page: via page-wide metadata :html_theme.sidebar_secondary.remove: or via html_theme_options in conf.py and set the "secondary_sidebar_items" for a particular page into an empty list. However, they do not seem to behave consistently. In particular, when removing via conf (e.g. https://pydata-sphinx-theme.readthedocs.io/en/latest/examples/no-sidebar.html) the secondary sidebar actually still exists and takes up width, though empty. When removing via page-wide metadata (e.g. https://pydata-sphinx-theme.readthedocs.io/en/latest/examples/in-page-toc.html) the secondary sidebar is completely removed.

I also constructed minimal reproducible examples here. You may compare these two pages:

https://charlie-xiao.github.io/pst-testing-website-0-15-2/issue-1686/remove_with_conf.html https://charlie-xiao.github.io/pst-testing-website-0-15-2/issue-1686/remove_with_meta.html

Charlie-XIAO commented 6 months ago

So the problem seems to be here:

https://github.com/pydata/pydata-sphinx-theme/blob/11af3fcfdcac4f58dfaee97d0da458cb9bbb6933/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html#L10

When secondary_sidebar_items is a dictionary, even if for this page we have an empty list not theme_secondary_sidebar_items will evaluate the whole dictionary and thus is false. We should alternatively use secondary_sidebar_items which is an array set by set_secondary_sidebar_items() in utils.py, as is done in sidebar-secondary.html. I opened #1688 for this, together with a test.