Skip to content

Commit

Permalink
Support setting number of header links
Browse files Browse the repository at this point in the history
Now users can set

[sphinx.theme]
header_links_before_dropdown = 4

rather than extending conf.py.
  • Loading branch information
jonathansick committed Sep 13, 2022
1 parent b523af3 commit 154eca3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions docs/project-guides/guides/toml-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ If the Python API is oriented towards contributors, such as in an application or

Configurations related to the Sphinx HTML theme.

header_links_before_dropdown
----------------------------

|optional|

Number of links to show in the navigation head before folding extra items into a "More" dropdown.
The default is 5.

If the section titles are long you may need to reduce this number.

.. _guide-project-show-github-edit-link:

show_github_edit_link
Expand Down
20 changes: 19 additions & 1 deletion src/documenteer/conf/_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ class ThemeModel(BaseModel):
True, description="Show a link to edit on GitHub if True"
)

header_links_before_dropdown: int = Field(
5,
description=(
"Number of links in the header nav before showing a 'More' "
"dropdown."
),
)


class SphinxModel(BaseModel):
"""Model for Sphinx configurations in documenteer.toml."""
Expand Down Expand Up @@ -194,7 +202,7 @@ class SphinxModel(BaseModel):
),
)

theme: ThemeModel
theme: ThemeModel = Field(default_factory=lambda: ThemeModel())

intersphinx: Optional[IntersphinxModel]

Expand Down Expand Up @@ -463,3 +471,13 @@ def set_edit_on_github(
"github_version"
] = self.conf.project.github_default_branch
html_context["doc_path"] = doc_dir

@property
def header_links_before_dropdown(self) -> int:
"""Number of links to show in the nav head before folding extra items
into a More dropdown.
"""
if self.conf.sphinx:
return self.conf.sphinx.theme.header_links_before_dropdown
else:
return 5
2 changes: 1 addition & 1 deletion src/documenteer/conf/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
"header_links_before_dropdown": 5,
"header_links_before_dropdown": _conf.header_links_before_dropdown,
"external_links": [{"name": "Rubin docs", "url": "https://www.lsst.io"}],
"icon_links": [],
"logo": {
Expand Down

0 comments on commit 154eca3

Please sign in to comment.