{% comment %} ============================================================================== Extract the active nav IDs. ============================================================================== {% endcomment %} {% assign active_nav_ids = site.array %} {% assign parent_id = page.nav-parent_id %} {% for i in (1..10) %} {% if parent_id %} {% assign active_nav_ids = active_nav_ids | push: parent_id %} {% assign current = (site.pages | where: "nav-id" , parent_id | sort: "nav-pos") %} {% if current.size > 0 %} {% assign parent_id = current[0].nav-parent_id %} {% else %} {% break %} {% endif %} {% else %} {% break %} {% endif %} {% endfor %} {% comment %} ============================================================================== Build the nested list from nav-id and nav-parent_id relations. ============================================================================== This builds a nested list from all pages. The fields used to determine the structure are: - 'nav-id' => ID of this page. Other pages can use this ID as their parent ID. - 'nav-parent_id' => ID of the parent. This page will be listed under the page with id 'nav-parent_id'. Level 0 is made up of all pages, which have nav-parent_id set to 'root'. The 'title' of the page is used as the default link text. You can override this via 'nav-title'. The relative position per navigational level is determined by 'nav-pos'. {% endcomment %} {% assign elementsPosStack = site.array %} {% assign posStack = site.array %} {% assign elements = site.array %} {% assign children = (site.pages | where: "nav-parent_id" , "root" | sort: "nav-pos") %} {% if children.size > 0 %} {% assign elements = elements | push: children %} {% endif %} {% assign elementsPos = 0 %} {% assign pos = 0 %} {% assign elementsPosStack = elementsPosStack | pop %} {% assign posStack = posStack | pop %} {% endif %} {% else %} {% assign this = elements[elementsPos][pos] %} {% if this.url == page.url %} {% assign active = true %} {% elsif this.nav-id and active_nav_ids contains this.nav-id %} {% assign active = true %} {% else %} {% assign active = false %} {% endif %} {% capture title %}{% if this.nav-title %}{{ this.nav-title }}{% else %}{{ this.title }}{% endif %}{% endcapture %} {% capture target %}"{{ site.baseurl }}{{ this.url }}"{% if active %} class="active"{% endif %}{% endcapture %} {% capture overview_target %}"{{ site.baseurl }}{{ this.url }}"{% if this.url == page.url %} class="active"{% endif %}{% endcapture %} {% if this.section-break %}
{% endif %} {% assign pos = pos | plus: 1 %} {% if this.nav-id %} {% assign children = (site.pages | where: "nav-parent_id" , this.nav-id | sort: "nav-pos") %} {% if children.size > 0 %} {% capture collapse_target %}"#collapse-{{ i }}" data-toggle="collapse"{% if active %} class="active"{% endif %}{% endcapture %} {% capture expand %}{% unless active %} {% endunless %}{% endcapture %}
  • {{ title }}{{ expand }}