Skip to content
Closed
Show file tree
Hide file tree
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
32 changes: 32 additions & 0 deletions pandas_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,40 @@ def get_page_toc_object():
except:
return {}

def nav_to_html_list(nav, level=1, include_item_names=False):
if len(nav) == 0:
return ''
ul = [f'<ul class="nav sidenav_l{level}">']
# If we don't include parents, next `ul` should be the same level
next_level = level+1 if include_item_names else level

for child in nav:
# If we're not rendering title names and have no children, skip
if not (include_item_names or child['children']):
continue
active = 'active' if child['active'] else ''
ul.append(" " + f'<li class="{active}">')
# Render links for the top-level names if we wish
if include_item_names:
ul.append(" "*2 + f'<a href="{ child["url"] }">{ child["title"] }</a>')

# Render HTML lists for children
if child["children"]:
# Always include the names of the children
child_list = nav_to_html_list(child["children"], level=next_level, include_item_names=True)
ul.append(child_list)
ul.append(" " + '</li>')
ul.append("</ul>")

# Now add indentation for our level
base_indent = " " * (level - 1)
ul = [base_indent + line for line in ul]
ul = '\n'.join(ul)
return ul

ctx["get_nav_object"] = get_nav_object
ctx["get_page_toc_object"] = get_page_toc_object
ctx["nav_to_html_list"] = nav_to_html_list
return None


Expand Down
30 changes: 1 addition & 29 deletions pandas_sphinx_theme/docs-sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,6 @@
</form>

<nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">

<div class="bd-toc-item active">
{% set nav = get_nav_object(maxdepth=3, collapse=True) %}

<ul class="nav bd-sidenav">
{% for main_nav_item in nav %}
{% if main_nav_item.active %}
{% for nav_item in main_nav_item.children %}
{% if nav_item.children %}

<li class="{% if nav_item.active%}active{% endif %}">
<a href="{{ nav_item.url }}">{{ nav_item.title }}</a>
<ul>
{% for nav_item in nav_item.children %}
<li class="{% if nav_item.active%}active{% endif %}">
<a href="{{ nav_item.url }}">{{ nav_item.title }}</a>
</li>
{% endfor %}
</ul>
</li>
{% else %}
<li class="{% if nav_item.active%}active{% endif %}">
<a href="{{ nav_item.url }}">{{ nav_item.title }}</a>
</li>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
</ul>

{{ nav_to_html_list(nav) }}
</nav>
2 changes: 1 addition & 1 deletion pandas_sphinx_theme/static/css/theme.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 21 additions & 32 deletions src/scss/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,28 @@
}
}

.bd-sidebar .nav > {
li > a {
display: block;
padding: 0.25rem 1.5rem;
font-size: 90%;
color: rgba(0, 0, 0, 0.65);
.bd-sidebar .nav {
list-style: none;
padding: 0.25rem 1.5rem;

&:hover {
color: rgba(0, 0, 0, 0.85);
text-decoration: none;
background-color: transparent;
&.sidenav_l1 {
padding: 0.25rem 0rem;
}

li {
width: 100%;

> a {
display: block;
padding: 0.25rem 1.5rem;
font-size: 90%;
color: rgba(0, 0, 0, 0.65);

&:hover {
color: rgba(0, 0, 0, 0.85);
text-decoration: none;
background-color: transparent;
}
}
}

Expand All @@ -201,28 +212,6 @@
background-color: transparent; */
}
}

li > ul {
list-style: none;
padding: 0.25rem 1.5rem;

> {
li > a {
display: block;
padding: 0.25rem 1.5rem;
font-size: 90%;
color: rgba(0, 0, 0, 0.65);
}

.active {
> a,
&:hover > a {
font-weight: 600;
color: #130654;
}
}
}
}
}

/* offsetting html anchor titles to adjust for fixed header, https://github.com/pandas-dev/pandas-sphinx-theme/issues/6*/
Expand Down