Implemented new template and optimized navigation

This commit is contained in:
2025-03-16 18:42:03 +01:00
parent 3e1a9e9dde
commit 18fba35173
5 changed files with 56 additions and 39 deletions

View File

@@ -1,25 +1,19 @@
{% macro render_headings(headings) %}
<ul>
{% for item in headings %}
<li>
<a href="{{ pathto(item.link).replace("#", "") + '#' + item.anchor }}">{{ item.text }}</a>
{% if item.children %}
{{ render_headings(item.children) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endmacro %}
{% if local_md_headings %}
<div class="local-md-headings">
<h3>Page Headings</h3>
{% set ns = namespace(current_level=0) %}
{% for item in local_md_headings %}
{# If the current heading level is greater than the previous, open new <ul> tags #}
{% if item.level > ns.current_level %}
{% for i in range(ns.current_level, item.level) %}
<ul>
{% endfor %}
{# If the current heading level is less than the previous, close the open <ul> tags #}
{% elif item.level < ns.current_level %}
{% for i in range(item.level, ns.current_level) %}
</ul>
{% endfor %}
{% endif %}
<li><a href="{{ pathto(item.link).replace("#","") + "#" + item.anchor}}">{{ item.text }}</a></li>
{% set ns.current_level = item.level %}
{% endfor %}
{# Close any remaining open <ul> tags #}
{% for i in range(ns.current_level) %}
</ul>
{% endfor %}
{{ render_headings(local_md_headings) }}
</div>
{% endif %}