-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganises navigation macro into own section
- Loading branch information
Showing
2 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -%} | ||
<li class="{{class}}" data-expand-tag="{{subsection.path}}"> | ||
<span style="padding-left: {{depthIndent}}px" class="flex flex-row{{spanClass}}"> | ||
<span class="px-1"><i class="fa-solid fa-caret-right text-blue-300 {{iconClass}} nav-toggle cursor-pointer"></i></span> | ||
<a href="{{ subsection.permalink | safe }}" class="{{linkClass}}"> | ||
{{ subsection.title }} | ||
</a> | ||
</span> | ||
{%- if subsection.subsections -%} | ||
<ul> | ||
{%- for lowerSubPath in subsection.subsections | sort -%} | ||
{% set prod = get_env(name="ZOLA_ENV", default="dev") != "prod" %} | ||
{% set lowerSubsection = get_section(path=lowerSubPath, metadata_only=prod) %}{# TODO: this is the most expensive call to get_section() we have, need to optimize to save 20s #} | ||
{{- self::render_subsection(currentPage = currentPage, subsection=lowerSubsection, depth=depth+1) -}} | ||
{%- endfor -%} | ||
</ul> | ||
{%- endif -%} | ||
|
||
{%- if subsection.pages -%} | ||
<ul> | ||
{%- for page in subsection.pages | sort(attribute="title") -%} | ||
{{- self::render_subsection_pages(page=page, currentPage=currentPage, subsection=subsection, depth=depth, currentParent=myParentSection) -}} | ||
{%- endfor -%} | ||
</ul> | ||
{%- endif -%} | ||
</li> | ||
{% endmacro render_subsection %} | ||
|
||
{% macro render_subsection_pages(page, currentPage, subsection, depth, currentParent) %} | ||
{%- set renderAll = false %} | ||
{%- for page in currentPage.ancestors %} | ||
{%- set iteratorSection = get_section(path=page, metadata_only=true) %} | ||
{%- if iteratorSection.path == subsection.path %} | ||
{%- set_global renderAll = true %} | ||
{%- break %} | ||
{%- endif %} | ||
{%- endfor %} | ||
|
||
{%- if depth > 0 | ||
and current_path != subsection.path | ||
and currentParent.path != subsection.path | ||
and not renderAll %} | ||
{%- set class = "hidden" %} | ||
{%- else %} | ||
{%- set class = "" %} | ||
{%- endif -%} | ||
|
||
{%- set spanClass = " nav-link-inactive" -%} | ||
{%- if current_path == page.path %} | ||
{%- set spanClass = " nav-link-active" %} | ||
{%- endif -%} | ||
|
||
{%- set depthIndent = 20 * (depth + 1) -%} | ||
<li class="text-title {{class}}"> | ||
<span style="padding-left: {{depthIndent}}px" class="flex flex-row{{spanClass}}"> | ||
<span><i class="fa-solid fa-minus"></i></span> | ||
<a href="{{ page.permalink | safe }}"> | ||
{{ page.title }} | ||
</a> | ||
</span> | ||
</li> | ||
{% endmacro %} |