From 0900f2910e908ff8c997b684c2f7ae69791f50de Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 1 Jun 2022 16:41:21 +0200 Subject: Hierarchical navigation menu --- templates/_nav.html | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ templates/index.html | 56 +++++++++++++++------------------------------------- 2 files changed, 69 insertions(+), 40 deletions(-) create mode 100644 templates/_nav.html (limited to 'templates') diff --git a/templates/_nav.html b/templates/_nav.html new file mode 100644 index 0000000..92ed4c5 --- /dev/null +++ b/templates/_nav.html @@ -0,0 +1,53 @@ +{% macro navsection(hierarchy, level, current) %} + {% set sec = hierarchy | nth(n=level) %} + {% set sec = get_section(path=sec) %} + {% set maxlevel = hierarchy | length %} + + {% if sec.subsections %} + {% for s in sec.subsections %} + {% set p = get_section(path=s) %} +
+ {% if p.path == current.path %} + {{ p.title }} + {% elif hierarchy is containing(s) %} + ⯆ {{ p.title }} + {% else %} + ⯈ {{ p.title }} + {% endif %} + {% if hierarchy is containing(s) or current.path == p.path %} + {% if level + 1 < maxlevel %} + {{ nav::navsection(hierarchy=hierarchy,level=level + 1,current=current) }} + {% endif %} + {% endif %} +
+ {% endfor %} + {% endif %} + + {% if sec.pages %} + {% for p in sec.pages %} +
+ {% if p.path == current.path %} +   {{ p.title }} + {% else %} +   {{ p.title }} + {% endif %} +
+ {% endfor %} + {% endif %} +{% endmacro navsection %} + +{% macro navmenu(current) %} + {% if current.ancestors %} + {% set hierarchy = current.ancestors | concat(with=current.relative_path) %} + {% else %} + {% set hierarchy = [current.relative_path] %} + {% endif %} + + {% set root_path = hierarchy | nth(n=0) %} + {% set root = get_section(path=root_path) %} +
+ {{ root.title }} +
+ + {{ nav::navsection(hierarchy=hierarchy,level=0,current=current) }} +{% endmacro %} diff --git a/templates/index.html b/templates/index.html index 54fb473..004a4fa 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,4 +1,5 @@ {% import "_macros.html" as macros %} +{% import "_nav.html" as nav %} @@ -7,7 +8,7 @@ {% block title %}{{ config.title }}{% endblock title %} {% block favicon %} - + {% endblock favicon %} {% include "_variables.html" %} @@ -24,46 +25,21 @@ {% endblock header %}
- {% block toc %} - {% if page.ancestors %} - {% set section = get_section(path=page.ancestors | last) %} - {% endif %} - {% if section.ancestors %} - {% set parent = get_section(path=section.ancestors | last) %} - {% endif %} + {% block toc %}
-
- - {% if section.subsections %} - {% for s in section.subsections %} - {% set p = get_section(path=s) %} - - {% endfor %} - {% endif %} - - {% if section.pages %} - {% for p in section.pages %} - - {% endfor %} - {% endif %} - {% if parent %} - - {% endif %} -
+
+ {% if page %} + {{ nav::navmenu(current=page) }} + {% else %} + {{ nav::navmenu(current=section) }} + {% endif %} +
- {% endblock toc %} + {% endblock toc %}
{% block content %} -
{{ section.title }}
+
{{ section.title }}
{{ section.content | safe }} {% endblock content %}
@@ -75,10 +51,10 @@ {% block footer %} {% endblock footer %} -- cgit v1.2.3