From 0c0ceaee140aa66a2a6faf8bd225d3891735e761 Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Wed, 7 Sep 2022 09:37:40 +0200 Subject: [PATCH] ENH: Use toctree titles in the header navbar (#915) --- src/pydata_sphinx_theme/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pydata_sphinx_theme/__init__.py b/src/pydata_sphinx_theme/__init__.py index ed14627db..ba8a15a93 100644 --- a/src/pydata_sphinx_theme/__init__.py +++ b/src/pydata_sphinx_theme/__init__.py @@ -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"""