diff --git a/templates/_nav.html b/templates/_nav.html new file mode 100644 index 0000000..9b76c96 --- /dev/null +++ b/templates/_nav.html @@ -0,0 +1,61 @@ +{% 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.subsections or p.pages %} + {% 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 %} + {% else %} + {% if p.path == current.path %} + {{ p.title }} + {% else %} + {{ p.title }} + {% 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 | slice(start=1) | 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 %}