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

ENH: Use toctree titles in the header navbar #915

Merged
merged 1 commit into from Sep 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/pydata_sphinx_theme/__init__.py
Expand Up @@ -238,16 +238,17 @@ def generate_header_nav_html(n_links_before_dropdown=5):

# Find the root document because it lists our top-level toctree pages
root = app.env.tocs[app.config.root_doc]

# Iterate through each toctree node in the root document
# Grab the toctree pages and find the relative link + title.
links_html = []
# Can just use "findall" once docutils min version >=0.18.1
meth = "findall" if hasattr(root, "findall") else "traverse"
for toc in getattr(root, meth)(toctree_node):
for _, page in toc.attributes["entries"]:
for title, page in toc.attributes["entries"]:
# If this is the active ancestor page, add a class so we highlight it
current = " current active" if page == active_header_page else ""
title = app.env.titles[page].astext()
title = title if title else app.env.titles[page].astext()
links_html.append(
f"""
<li class="nav-item{current}">
Expand Down