From 7e3fc879c28f0123bd1899018193d798761e20da Mon Sep 17 00:00:00 2001 From: harryob <55142896+harryob@users.noreply.github.com> Date: Mon, 5 Aug 2024 20:22:42 +0100 Subject: [PATCH] reorganises navigation macro into own section --- templates/base.html | 3 +- templates/navigation.html | 112 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 templates/navigation.html diff --git a/templates/base.html b/templates/base.html index 6a2adbcbc..c2b370737 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,4 +1,5 @@ {% import "macros.html" as macros %} +{% import "navigation.html" as navigation %} {%- if page -%} {% set pageOrSubsection = page -%} @@ -58,7 +59,7 @@ {%- set index = get_section(path="_index.md", metadata_only=true) -%} {%- for subsectionPath in index.subsections | sort -%} {%- set subsection = get_section(path=subsectionPath) -%} - {{ macros::render_subsection(currentPage=pageOrSubsection, subsection=subsection, depth=0) -}} + {{ navigation::render_subsection(currentPage=pageOrSubsection, subsection=subsection, depth=0) -}} {%- endfor -%} {%- endblock menu -%} diff --git a/templates/navigation.html b/templates/navigation.html new file mode 100644 index 000000000..8bbcc2351 --- /dev/null +++ b/templates/navigation.html @@ -0,0 +1,112 @@ +{% macro render_subsection(currentPage, subsection, depth) %} + {%- if currentPage.ancestors | length %} + {%- set myParent = currentPage.ancestors | last -%} + {%- else %} + {%- set myParent = subsection.ancestors | last %} + {%- endif %} + + {%- set myParentSection = get_section(path=myParent, metadata_only=true) -%} + + {%- set subsectionParentUrl = subsection.ancestors | last %} + {%- set subsectionParent = get_section(path=subsectionParentUrl, metadata_only=true) %} + + {%- set renderAll = false %} + {%- for page in currentPage.ancestors %} + {%- set iteratorSection = get_section(path=page, metadata_only=true) %} + {%- if iteratorSection.path == subsectionParent.path %} + {%- set_global renderAll = true %} + {%- break %} + {%- endif %} + {%- endfor %} + + {%- if depth > 1 + and current_path != subsection.path + and current_path != myParentSection.path + and current_path != subsectionParent.path + and not renderAll %} + {%- set class = "hidden" %} + {%- else %} + {%- set class = "" %} + {%- endif %} + + {%- set linkClass = "" %} + {%- set firstChar = subsection.title | split(pat="") | nth(n = 1) -%} + {%- if firstChar == "/" -%} + {%- set class = class ~ " code-nav" %} + {%- set linkClass = "type" %} + {%- else %} + {%- set class = class ~ " text-title" %} + {%- endif -%} + + {%- set iconClass = "" -%} + {%- if currentPage.ancestors is containing(subsection.relative_path) or current_path == subsection.path or 1 > depth -%} + {%- set iconClass = "fa-rotate-90" -%} + {%- endif -%} + + {%- set spanClass = " nav-link-inactive" -%} + {%- if current_path == subsection.path %} + {%- set spanClass = " nav-link-active" %} + {%- endif -%} + + {%- set depthIndent = 20 * depth -%} +