Skip to content

Commit

Permalink
ENH: Use toctree titles in the header navbar (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau committed Sep 7, 2022
1 parent 790e676 commit 0c0ceae
Showing 1 changed file with 3 additions and 2 deletions.
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

0 comments on commit 0c0ceae

Please sign in to comment.