check for active children in submenus (#1869)

This patch checks, if the title of the current page matches with the
title of a submenu child. If so, it sets the submenu and the
corresponding child as active, highlighting it in the header.
This commit is contained in:
Tianmaru 2023-12-25 02:01:38 +01:00 committed by GitHub
parent 1fa3febcc7
commit a1a9250b93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -67,9 +67,15 @@
{%- for p in sorted_pages -%}
{%- if p.nav and p.autogen == nil -%}
{%- if p.dropdown %}
<li class="nav-item dropdown {% if page.title == p.title %}active{% endif %}">
{%- assign has_active_child = false -%}
{%- for child in p.children -%}
{%- if page.title == child.title -%}
{%- assign has_active_child = true -%}
{%- endif -%}
{%- endfor -%}
<li class="nav-item dropdown {% if page.title == p.title or has_active_child %}active{% endif %}">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{ p.title }}
{%- if page.title == p.title -%}
{%- if page.title == p.title or has_active_child -%}
<span class="sr-only">(current)</span>
{%- endif -%}
</a>
@ -78,7 +84,7 @@
{%- if child.title == 'divider' %}
<div class="dropdown-divider"></div>
{%- else %}
<a class="dropdown-item" href="{{ child.permalink | relative_url }}">{{ child.title }}</a>
<a class="dropdown-item {% if page.title == child.title %}active{% endif %}" href="{{ child.permalink | relative_url }}">{{ child.title }}</a>
{%- endif -%}
{% endfor %}
</div>