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

👌 IMPROVE: Master doc title specified in _toc.yml is visible in left-sidebar #304

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions sphinx_book_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from sphinx.application import Sphinx
from sphinx.locale import get_translation
from sphinx.util import logging
from contextlib import suppress

from .launch import add_hub_urls
from . import static as theme_static
Expand Down Expand Up @@ -125,10 +126,18 @@ def generate_nav_html(
master_doc = config["master_doc"]
master_doctree = app.env.get_doctree(master_doc)
master_url = context["pathto"](master_doc)
master_title = list(master_doctree.traverse(nodes.title))
if len(master_title) == 0:
raise ValueError(f"Landing page missing a title: {master_doc}")
master_title = master_title[0].astext()

# check title in globaltoc (jb case) else get title from doctree
master_title = None
with suppress(Exception):
master_title = app.config["globaltoc"].get("title")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note this won't work quite the same with jupyter-book/jupyter-book#1293. But I would be interested if there is a less theme specific solution that could go straight into sphinx-external-toc 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisjsewell you mean creating a global variable in sphinx-external-toc which has this value? and can be accessed directly in any theme.


if not master_title:
master_title = list(master_doctree.traverse(nodes.title))
if len(master_title) == 0:
raise ValueError(f"Landing page missing a title: {master_doc}")
master_title = master_title[0].astext()

li_class = "toctree-l1"
if context["pagename"] == master_doc:
li_class += " current"
Expand Down