{% 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.lighter %}
← {{ page.lighter.title }}
{% 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 }}
{% 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 }}
{% 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.heavier %}
{{ page.heavier.title }} →
{% 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 }} →
{% 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 }} →
{% endif %} {# no break #} {% set_global found_current = false %} {% endif %} {% endif %} {% endfor %} {% endif %}
{% endmacro %}