Skip to content

Commit 1eda93a

Browse files
Fix 2nd navigation level in left sidebar (pandas-dev#31)
1 parent 74bb98a commit 1eda93a

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

pandas_sphinx_theme/__init__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
# Sphinx monkeypatch for adding toctree objects into context
1818

1919

20-
def convert_docutils_node(list_item):
20+
def convert_docutils_node(list_item, only_pages=False):
2121
if not list_item.children:
2222
return None
2323
reference = list_item.children[0].children[0]
2424
title = reference.astext()
2525
url = reference.attributes["refuri"]
2626
active = "current" in list_item.attributes["classes"]
2727

28+
if only_pages and '#' in url:
29+
return None
30+
2831
nav = {}
2932
nav["title"] = title
3033
nav["url"] = url
@@ -33,7 +36,7 @@ def convert_docutils_node(list_item):
3336

3437
if len(list_item.children) > 1:
3538
for child_item in list_item.children[1].children:
36-
child_nav = convert_docutils_node(child_item)
39+
child_nav = convert_docutils_node(child_item, only_pages=only_pages)
3740
if child_nav is not None:
3841
nav["children"].append(child_nav)
3942

@@ -50,7 +53,7 @@ def get_nav_object(**kwds):
5053

5154
nav = []
5255
for child in toctree.children[0].children:
53-
child_nav = convert_docutils_node(child)
56+
child_nav = convert_docutils_node(child, only_pages=True)
5457
nav.append(child_nav)
5558

5659
return nav

pandas_sphinx_theme/docs-sidebar.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
<nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
88

99
<div class="bd-toc-item active">
10-
{% set nav = get_nav_object(maxdepth=2) %}
10+
{% set nav = get_nav_object(maxdepth=3) %}
1111

1212
<ul class="nav bd-sidenav">
1313
{% for main_nav_item in nav %}
1414
{% if main_nav_item.active %}
1515
{% for nav_item in main_nav_item.children %}
1616
{% if nav_item.children %}
1717

18-
<li>{{ nav_item.title }}
18+
<li class="{% if nav_item.active%}active{% endif %}">
19+
<a href="{{ nav_item.url }}">{{ nav_item.title }}</a>
1920
<ul>
2021
{% for nav_item in nav_item.children %}
21-
<li class="{% if nav_item.active%}active bd-sidenav-active{% endif %}">
22+
<li class="{% if nav_item.active%}active{% endif %}">
2223
<a href="{{ nav_item.url }}">{{ nav_item.title }}</a>
2324
</li>
2425
{% endfor %}

pandas_sphinx_theme/static/css/custom.css

+20-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
.bd-toc-item.active > .bd-sidenav {
160160
display: block;
161161
}
162-
162+
163163
.bd-sidebar .nav > li > a {
164164
display: block;
165165
padding: .25rem 1.5rem;
@@ -183,7 +183,25 @@
183183
background-color: transparent; */
184184
}
185185

186-
186+
.bd-sidebar .nav > li > ul {
187+
list-style: none;
188+
padding: .25rem 1.5rem;
189+
}
190+
191+
.bd-sidebar .nav > li > ul > li > a {
192+
display: block;
193+
padding: .25rem 1.5rem;
194+
font-size: 90%;
195+
color: rgba(0, 0, 0, 0.65);
196+
}
197+
198+
.bd-sidebar .nav > li > ul > .active > a,
199+
.bd-sidebar .nav > li > ul > .active:hover > a {
200+
font-weight: 600;
201+
background: #007bff;
202+
color: white;
203+
}
204+
187205
/* offsetting html anchor titles to adjust for fixed header, https://github.com/pandas-dev/pandas-sphinx-theme/issues/6*/
188206
h2::before, h3::before,
189207
h4::before, h5::before,

0 commit comments

Comments
 (0)