aboutsummaryrefslogtreecommitdiff
path: root/templates/_nav.html
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-06-01 16:41:21 +0200
committerAlex Auvolat <alex@adnab.me>2022-06-01 16:44:36 +0200
commit0900f2910e908ff8c997b684c2f7ae69791f50de (patch)
tree716428ea37858c69672e749e151b4345357e319a /templates/_nav.html
parent40596285a182ddd469422de25f7c78bcef098953 (diff)
downloadguide.deuxfleurs.fr-0900f2910e908ff8c997b684c2f7ae69791f50de.tar.gz
guide.deuxfleurs.fr-0900f2910e908ff8c997b684c2f7ae69791f50de.zip
Hierarchical navigation menu
Diffstat (limited to 'templates/_nav.html')
-rw-r--r--templates/_nav.html53
1 files changed, 53 insertions, 0 deletions
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) %}
+ <div class="toc-item">
+ {% if p.path == current.path %}
+ <a class="subtext" href="{{ p.permalink | safe}}">⯆ <b>{{ p.title }}</b></a>
+ {% elif hierarchy is containing(s) %}
+ <a class="subtext" href="{{ p.permalink | safe}}">⯆ {{ p.title }}</a>
+ {% else %}
+ <a class="subtext" href="{{ p.permalink | safe}}">⯈ {{ p.title }}</a>
+ {% 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 %}
+ </div>
+ {% endfor %}
+ {% endif %}
+
+ {% if sec.pages %}
+ {% for p in sec.pages %}
+ <div class="toc-item">
+ {% if p.path == current.path %}
+ <a class="subtext" href="{{p.permalink | safe}}">&nbsp;&nbsp;<b>{{ p.title }}</b></a>
+ {% else %}
+ <a class="subtext" href="{{p.permalink | safe}}">&nbsp;&nbsp;{{ p.title }}</a>
+ {% endif %}
+ </div>
+ {% 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) %}
+ <div class="toc-item toc-section">
+ <a class="subtext" href="{{root.permalink | safe}}">{{ root.title }}</a>
+ </div>
+
+ {{ nav::navsection(hierarchy=hierarchy,level=0,current=current) }}
+{% endmacro %}