From f3b7e90693bf2b51a53a23d98a60bbf04065103a Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 1 Mar 2023 19:45:01 +0100 Subject: rework infrastructures --- templates/_nav.html | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'templates/_nav.html') diff --git a/templates/_nav.html b/templates/_nav.html index b183a57..0ab8ac7 100644 --- a/templates/_nav.html +++ b/templates/_nav.html @@ -9,6 +9,7 @@ {{ nav::inner_nav(root=target, current=target) }} {% endmacro %} +{# -------------------------- #} {# -------------------------- #} {# (Private) Shared+root logic to build the menu #} @@ -34,7 +35,7 @@ {% endif %} {% endmacro %} -{# On small screens, like a smartphone, hide the menu behind an hamburger icon #} +{# (Private) On small screens, like a smartphone, hide the menu behind an hamburger icon #} {% macro hamburger(root) %} {% endmacro %} -{# Build a breadcrumb for the page #} +{# (Private) Build a breadcrumb for the page #} {# It's ugly because this is the hacky part of the project #} {% macro breadcrumb(corpus, root, target) %}{% if 'parent' in target.extra and target.extra.parent != root %}{% set new_target = get_page(path=target.extra.parent) %}{{ nav::breadcrumb(corpus=corpus, root=root, target=new_target) }}:{{ new_target.relative_path }}{% endif %}{% endmacro %} +{# (Private) Render a list menu (this is the simple fallback when extra.parent is not defined #} {% macro list(list, selected) %} {% for page in list %} {% set is_selected = page.relative_path == selected.relative_path %} @@ -56,26 +58,27 @@ {% endfor %} {% endmacro %} -{# Tree menu rendering #} +{# (Private) Tree menu rendering; this function is recursive #} +{# this function takes a breadcrumb to know which part of the menu must be unfolded #} {% macro tree(tree, cursor, selected, crumb) %} {% for page in tree | get(key=cursor) %} {% set is_selected = page.relative_path == selected.relative_path %}
- {# LINK WITH SUBSECTION #} + {# Link with a (possible) subsection #} {% if page.relative_path in tree %} + {# Display link as a section #} {{ nav::link(page=page, is_selected=is_selected, is_parent=true) }} + + {# Should we unroll this part of the tree? #} {% if page.relative_path in crumb or is_selected %} {% endif %} - {# SIMPLE LINK #} + {# Simple link, ie. a leaf of the tree #} {% else %} {{ nav::link(page=page, is_selected=is_selected, is_parent=false) }} {% endif %} @@ -83,10 +86,7 @@ {% endfor %} {% endmacro %} -{% macro subsection() %} - -{% endmacro %} - +{# (Private) Render a single link #} {% macro link(page, is_selected, is_parent) %} {% if is_selected %}{% endif %} -- cgit v1.2.3