Back to Loco

Docs Navigation

docs-site/templates/macros/docs-navigation.html

0.16.42.6 KB
Original Source

{% macro docs_navigation(page, current_section) %}

{# Find lighter navigation. There are three types: #} {# 1. directly find the lighter if exists, #} {# 2. find the last page in the previous sibling section, and #} {# 3. find the last page in the parent section. #} {% if page.lower %} [

← {{ page.lower.title }}

]({{%20page.lower.permalink%20}}) {% elif not page.extra.top %} {% set index = get_section(path=page.ancestors | reverse | first) %} {% set parent = get_section(path=index.ancestors | reverse | first)%} {% set first_subsection = get_section(path=parent.subsections | first) %} {% if index == first_subsection %} {% if parent.pages %} {% set last_page = parent.pages | last %} [

← {{ last_page.title }}

]({{%20last_page.permalink%20}}) {% endif %} {% else %} {% for s in parent.subsections | reverse %} {% set subsection = get_section(path=s) %} {% if subsection.permalink == index.permalink %} {% set_global found_current = true %} {% else %} {% if found_current %} {% if subsection.pages %} {% set last_page = subsection.pages | last %} [

← {{ last_page.title }}

]({{%20last_page.permalink%20}}) {% endif %} {# no break #} {% set_global found_current = false %} {% endif %} {% endif %} {% endfor %} {% endif %} {% endif %} {# Find heavier navigation. There are also three types: #} {# 1. directly find the heavier if exists, #} {# 2. find the first page in the subsection, and #} {# 3. find the first page in the next sibling section. #} {% if page.higher %} [

{{ page.higher.title }} →

]({{%20page.higher.permalink%20}}) {% elif page.extra.top %} {% set index_path = current_section ~ "/_index.md" | trim_start_matches(pat="/") %} {% set index = get_section(path=index_path) %} {% set first_subsection = get_section(path=index.subsections | first) %} {% if first_subsection.pages %} {% set first_page = first_subsection.pages | first %} [

{{ first_page.title }} →

]({{%20first_page.permalink%20}}) {% endif %} {% else %} {% set index = get_section(path=page.ancestors | reverse | first) %} {% set parent = get_section(path=index.ancestors | reverse | first)%} {% for s in parent.subsections %} {% set subsection = get_section(path=s) %} {% if subsection.permalink == index.permalink %} {% set_global found_current = true %} {% else %} {% if found_current %} {% if subsection.pages %} {% set first_page = subsection.pages | first %} [

{{ first_page.title }} →

]({{%20first_page.permalink%20}}) {% endif %} {# no break #} {% set_global found_current = false %} {% endif %} {% endif %} {% endfor %} {% endif %} {% endmacro %}