Skip to content

Don't show toctree hidden pages in left nav sidebar #2168

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

Closed
sarina opened this issue Mar 16, 2025 · 4 comments
Closed

Don't show toctree hidden pages in left nav sidebar #2168

sarina opened this issue Mar 16, 2025 · 4 comments
Labels
kind: bug Something isn't working needs: investigation Someone in the team needs to investigate and try and reproduce this issue

Comments

@sarina
Copy link

sarina commented Mar 16, 2025

Hi,

Is there a way to not show certain elements in the toctree in the left sidebar? Particularly we have some stuff in a hidden toctree that we don't want shown in the left sidebar.

In general it would be great to be able to exclude pages from the left sidebar nav, because space is at a premium.

Example: https://docs.openedx.org/en/latest/site_ops/install_configure_run_guide/index.html

The three "Deprecated" pages that appear in the left sidebar are in a hidden toctree that (correctly) don't appear on the index page.

Image

Thanks so much for any pointers or advice, I couldn't find anything in the docs.

@trallard trallard added kind: bug Something isn't working needs: investigation Someone in the team needs to investigate and try and reproduce this issue labels Mar 27, 2025
@trallard
Copy link
Collaborator

@sarina Thanks for opening this issue. I do not have an immediate response for you, but we will need to investigate.

@gabalafou would you be able to have a look at this and see if this can be reproduced?

@OriolAbril
Copy link
Contributor

I generally use the hidden option of toctrees when I want them to show on the side navbar but not on the page itself, so this change would be extremely disruptive for documentation built with the theme in mind and relying on this. To me this not only isn't a bug but it is a critical feature.

The description in the sphinx docs says the following:

A hidden toctree only defines the document hierarchy. It will not insert links into the document at the location of the directive.

This makes sense if you have other means of navigation, e.g. through manual links, HTML sidebar navigation, or if you use the :includehidden: option on the top-level toctree.

I interpret that as: when using hidden don't show the links in the place on the page where the directive is placed but do show them on other document hierarchy views like the sidebar.

For pages I don't want to show anywhere I use the orphan file-wide metadata or if they are too many pages and/or pages generated automatically the sphinx-remove-toctrees extension. @sarina do you think either of the two would fit your case?

@sarina
Copy link
Author

sarina commented Apr 30, 2025

@OriolAbril I appreciate the input & your perspective. I am on vacation now but I'll dig into this next week.

@gabalafou
Copy link
Collaborator

@sarina, you may have to take this issue to the Sphinx Book Theme, which is built on top of this theme. This theme already supports what you want via sidebar_includehidden, which is one of our theme configuration options.

Removing the problem with PyData Sphinx Theme

In fact, if I build the docs for openedx.org by adding the following lines to the bottom of Open edX's conf.py file:

# conf.py 

html_theme = "pydata_sphinx_theme"

html_theme_options = {
    "sidebar_includehidden": False
}

Then when I load the same page you linked above, the sidebar table of contents matches the index page—specifically, neither of them includes the hidden (deprecated) portions, as the following screenshot shows:

Pinpointing the problem in Sphinx Book Theme

I can take this one step further and pinpoint exactly where your problem occurs in the Sphinx Book Theme source code. It's on line 20 of the SBT sidebar nav template. The template passes includehidden=True to the generate_toctree_html() function. Compare that with our theme's equivalent sidebar nav template, which passes the theme configuration value to the function.

Possible Complications

One thing you should be aware of—you may have to do some playing around with the toctree directive on your site. It looks to me that you're using the :hidden: parameter in at least two different ways: one, to hide deprecated pages from appearing in the table of contents and two, to avoid duplicating links on the same index page. Your sidebar nav currently relies on Sphinx Book Theme passing includehidden=False. The moment you switch that to true, you will lose, for example, the "User Home Pages" section of the sidebar table of contents:

User Home Pages section of the table of contents

Conclusion

Since PST already supports the ability to NOT include hidden TOC trees, I'm closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working needs: investigation Someone in the team needs to investigate and try and reproduce this issue
Projects
None yet
Development

No branches or pull requests

4 participants