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

Add dropdown_text argument to generate_header_nav_html #1423

Merged
merged 3 commits into from Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions docs/conf.py
Expand Up @@ -129,6 +129,7 @@
},
],
"header_links_before_dropdown": 4,
"header_dropdown_text": "Other",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would not change the one from the docs (which should show a vanilla version of the documetnation as much as possible). Instead could you create a test in the test suits ? let us know if you don't understand how to override parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hope I got this right: f0cb271 =)

"icon_links": [
{
"name": "Twitter",
Expand Down
Expand Up @@ -6,6 +6,6 @@
{{ _("Site Navigation") }}
</p>
<ul class="bd-navbar-elements navbar-nav">
{{ generate_header_nav_html(n_links_before_dropdown=theme_header_links_before_dropdown) }}
{{ generate_header_nav_html(n_links_before_dropdown=theme_header_links_before_dropdown, dropdown_text=theme_header_dropdown_text) }}
</ul>
</nav>
Expand Up @@ -30,6 +30,7 @@ show_nav_level = 1
show_toc_level = 1
navbar_align = content
header_links_before_dropdown = 5
header_dropdown_text = "More"
switcher =
check_switcher = True
pygment_light_style = a11y-high-contrast-light
Expand Down
7 changes: 5 additions & 2 deletions src/pydata_sphinx_theme/toctree.py
Expand Up @@ -36,7 +36,9 @@ def add_toctree_functions(
"""Add functions so Jinja templates can add toctree objects."""

@lru_cache(maxsize=None)
def generate_header_nav_html(n_links_before_dropdown: int = 5) -> str:
def generate_header_nav_html(
n_links_before_dropdown: int = 5, dropdown_text: str = "More"
) -> str:
"""Generate top-level links that are meant for the header navigation.

We use this function instead of the TocTree-based one used for the
Expand All @@ -53,6 +55,7 @@ def generate_header_nav_html(n_links_before_dropdown: int = 5) -> str:

Parameters:
n_links_before_dropdown:The number of links to show before nesting the remaining links in a Dropdown element.
dropdown_text:Text of the dropdown element button.
"""
try:
n_links_before_dropdown = int(n_links_before_dropdown)
Expand Down Expand Up @@ -149,7 +152,7 @@ def generate_header_nav_html(n_links_before_dropdown: int = 5) -> str:
out += f"""
<li class="nav-item dropdown">
<button class="btn dropdown-toggle nav-item" type="button" data-bs-toggle="dropdown" aria-expanded="false" aria-controls="pst-header-nav-more-links">
More
{dropdown_text}
AlenkaF marked this conversation as resolved.
Show resolved Hide resolved
</button>
<ul id="pst-header-nav-more-links" class="dropdown-menu">
{links_dropdown_html}
Expand Down