Skip to content

Commit

Permalink
Do not generate dropdown in sidebar.
Browse files Browse the repository at this point in the history
This should fix pydata#1735, it is complementary to pydata#1564 but with a different
approach.

Instead of generating the same navbar as the fullpage width one, it
generate one with no dropdowns, with this, any css that tries to make
downtown looks like normal links in html becomes unnecessary.
  • Loading branch information
Carreau committed Apr 23, 2024
1 parent ee322a7 commit 2af9eb7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
{% if theme_navbar_center %}
<div class="sidebar-header-items__center">
{% for navbar_item in theme_navbar_center %}
<div class="navbar-item">{% include navbar_item %}</div>
{#
we are in the sidebar for narrow screnns for example, we do not want
an dropdown, so set the max drop value to a large number Here 999.
#}
{% with theme_header_links_before_dropdown=999 %}
<div class="navbar-item">{% include navbar_item %}</div>
{% endwith %}
{% endfor %}
</div>
{% endif %}
Expand Down
16 changes: 13 additions & 3 deletions src/pydata_sphinx_theme/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from functools import cache
from itertools import count
from typing import Iterator, List, Union
from typing import Iterator, List, Tuple, Union
from urllib.parse import urlparse

import sphinx
Expand Down Expand Up @@ -101,8 +101,18 @@ def unique_html_id(base_id: str):
return next(get_or_create_id_generator(base_id))

@cache
def generate_header_nav_before_dropdown(n_links_before_dropdown):
"""The cacheable part."""
def generate_header_nav_before_dropdown(
n_links_before_dropdown,
) -> Tuple[str, List[str]]:
"""Return html for navbar and dropdown.
Given the number of links before the dropdown, return the html for the navbar,
as well as the list of links to but in a dropdown.
Returns:
- HTML str for the navbar
- list of HTML str for the dropdown
"""
try:
n_links_before_dropdown = int(n_links_before_dropdown)
except Exception:
Expand Down

0 comments on commit 2af9eb7

Please sign in to comment.