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 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 templates/_nav.html (limited to 'templates/_nav.html') 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 %} -- cgit v1.2.3