feat(nav): add context-aware expansion for nested navigation
Children are only visible when user is viewing a page within that section. Uses Tera's starting_with test to detect ancestor relationship.
This commit is contained in:
6
docs/static/style.css
vendored
6
docs/static/style.css
vendored
@@ -98,11 +98,15 @@ body {
|
||||
margin-left: 1rem;
|
||||
padding-left: 0.5rem;
|
||||
border-left: 1px solid var(--border);
|
||||
display: flex;
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.sidebar .nav-children.expanded {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.sidebar .nav-children a {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
4
docs/templates/base.html
vendored
4
docs/templates/base.html
vendored
@@ -35,9 +35,11 @@
|
||||
</header>
|
||||
<nav>
|
||||
{% for item in nav %}
|
||||
{% set section_prefix = item.path | replace(from="index.html", to="") %}
|
||||
{% set is_current_section = page_path is starting_with(section_prefix) %}
|
||||
<a href="{{ prefix }}{{ item.path }}" {% if page_path==item.path %}class="active" {% endif %}>{{ item.label }}</a>
|
||||
{% if config.nested_nav and item.children %}
|
||||
<div class="nav-children">
|
||||
<div class="nav-children{% if is_current_section %} expanded{% endif %}">
|
||||
{% for child in item.children %}
|
||||
<a href="{{ prefix }}{{ child.path }}" {% if page_path==child.path %}class="active" {% endif %}>{{ child.label
|
||||
}}</a>
|
||||
|
||||
Reference in New Issue
Block a user