{# (Public) Entrypoint to be used by zola "pages" #} {% macro page(target) %} {% set root = get_section(path=target.ancestors | last) %} {{ nav::inner_nav(root=root, current=target) }} {% endmacro %} {# (Public) Entrypoint to be used by zola "sections" #} {% macro section(target) %} {{ nav::inner_nav(root=target, current=target) }} {% endmacro %} {# -------------------------- #} {# (Private) Shared+root logic to build the menu #} {% macro inner_nav(root, current) %} {{ nav::hamburger(root=root) }} {# Section title #}
{# Choose between "tree" (has extra.parent) and "list" (default) collections #} {% set root_tree = root.pages | group_by(attribute="extra.parent") %} {% if root.relative_path in root_tree %} {% set tree_breadcrumb = nav::breadcrumb(corpus=root.pages, root=root.relative_path, target=current)|split(pat=":")|slice(start=1) %} {{ nav::tree( tree=root_tree, cursor=root.relative_path, selected=current, crumb=tree_breadcrumb) }} {% else %} {{ nav::list(list=root.pages, selected=current) }} {% endif %} {% endmacro %} {# On small screens, like a smartphone, hide the menu behind an hamburger icon #} {% macro hamburger(root) %} {% endmacro %} {# 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 %} {% macro list(list, selected) %} {% for page in list %} {% set is_selected = page.relative_path == selected.relative_path %}