{%- 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_by_language[page.language] | 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 -%} {%- if page.language == "en" -%} {%- capture baseurl_i18n -%}{{ site.baseurl }}{%- endcapture -%} {%- else if page.language == "zh" -%} {%- capture baseurl_i18n -%}{{ site.baseurl }}/{{ page.language }}{%- endcapture -%} {%- endif -%} {%- 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 all_pages_by_nav_parent = (site.pages_by_language[page.language] | where_exp: "item", "item.nav-parent_id != nil" | group_by: "nav-parent_id") -%} {%- assign children = (all_pages_by_nav_parent | where: "name" , "root") -%} {%- assign children = (children[0].items | 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 = (all_pages_by_nav_parent | where: "name" , this.nav-id) -%} {%- if children.size > 0 -%} {%- assign children = (children[0].items | sort: "nav-pos") -%} {%- capture collapse_target -%}"#collapse-{{ i }}" data-toggle="collapse"{%- if active -%} class="active"{%- endif -%}{%- endcapture -%} {%- capture expand -%}{%- unless active -%} {%- endunless -%}{%- endcapture %}
  • {{ title }}{{ expand }}
    {%- if page.is_default_language -%} {%- else -%} {%- endif %}