mirror of
https://github.com/thangisme/notes.git
synced 2025-01-03 00:56:36 -05:00
Alphabetic navigation order
When `nav_order` is omitted, the order of nodes at each menu level (and in the auto-generated TOC) is alphabetical by `title`, instead of random. Any nodes with a specified `nav_order` precede all nodes at that level where it is omitted. Note that `nav_order` fields must have a uniform site-ide type: integers and strings cannot be mixed, otherwise Jekyll reports errors. The implementation filters the ordered and unordered pages from `site.html_pages`, sorts them separately, and concatenates the resulting arrays.
This commit is contained in:
parent
8bd2da55fe
commit
6660f442b0
@ -1,6 +1,8 @@
|
|||||||
<nav role="navigation" aria-label="Main navigation">
|
<nav role="navigation" aria-label="Main navigation">
|
||||||
<ul class="navigation-list">
|
<ul class="navigation-list">
|
||||||
{%- assign pages_list = site.html_pages | sort:"nav_order" -%}
|
{%- assign ordered_pages_list = site.html_pages | where_exp:"item", "item.nav_order != nil" | sort:"nav_order" -%}
|
||||||
|
{%- assign unordered_pages_list = site.html_pages | where_exp:"item", "item.nav_order == nil" | sort:"title" -%}
|
||||||
|
{%- assign pages_list = ordered_pages_list | concat: unordered_pages_list -%}
|
||||||
{%- for node in pages_list -%}
|
{%- for node in pages_list -%}
|
||||||
{%- unless node.nav_exclude -%}
|
{%- unless node.nav_exclude -%}
|
||||||
{%- if node.parent == nil -%}
|
{%- if node.parent == nil -%}
|
||||||
@ -10,7 +12,7 @@
|
|||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
<a href="{{ node.url | absolute_url }}" class="navigation-list-link{% if page.url == node.url %} active{% endif %}">{{ node.title }}</a>
|
<a href="{{ node.url | absolute_url }}" class="navigation-list-link{% if page.url == node.url %} active{% endif %}">{{ node.title }}</a>
|
||||||
{%- if node.has_children -%}
|
{%- if node.has_children -%}
|
||||||
{%- assign children_list = site.html_pages | where: "parent", node.title | sort:"nav_order" -%}
|
{%- assign children_list = pages_list | where: "parent", node.title -%}
|
||||||
<ul class="navigation-list-child-list ">
|
<ul class="navigation-list-child-list ">
|
||||||
{%- for child in children_list -%}
|
{%- for child in children_list -%}
|
||||||
<li class="navigation-list-item {% if page.url == child.url or page.parent == child.title %} active{% endif %}">
|
<li class="navigation-list-item {% if page.url == child.url or page.parent == child.title %} active{% endif %}">
|
||||||
@ -19,7 +21,7 @@
|
|||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
<a href="{{ child.url | absolute_url }}" class="navigation-list-link{% if page.url == child.url %} active{% endif %}">{{ child.title }}</a>
|
<a href="{{ child.url | absolute_url }}" class="navigation-list-link{% if page.url == child.url %} active{% endif %}">{{ child.title }}</a>
|
||||||
{%- if child.has_children -%}
|
{%- if child.has_children -%}
|
||||||
{%- assign grand_children_list = site.html_pages | where: "parent", child.title | sort:"nav_order" -%}
|
{%- assign grand_children_list = pages_list | where: "parent", child.title -%}
|
||||||
<ul class="navigation-list-child-list">
|
<ul class="navigation-list-child-list">
|
||||||
{%- for grand_child in grand_children_list -%}
|
{%- for grand_child in grand_children_list -%}
|
||||||
<li class="navigation-list-item {% if page.url == grand_child.url %} active{% endif %}">
|
<li class="navigation-list-item {% if page.url == grand_child.url %} active{% endif %}">
|
||||||
|
@ -74,9 +74,8 @@ layout: table_wrappers
|
|||||||
{% if page.has_children == true and page.has_toc != false %}
|
{% if page.has_children == true and page.has_toc != false %}
|
||||||
<hr>
|
<hr>
|
||||||
<h2 class="text-delta">Table of contents</h2>
|
<h2 class="text-delta">Table of contents</h2>
|
||||||
{% assign children_list = site.pages | sort:"nav_order" %}
|
|
||||||
<ul>
|
<ul>
|
||||||
{% for child in children_list %}
|
{% for child in pages_list %}
|
||||||
{% if child.parent == page.title and child.title != page.title %}
|
{% if child.parent == page.title and child.title != page.title %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ child.url | absolute_url }}">{{ child.title }}</a>{% if child.summary %} - {{ child.summary }}{% endif %}
|
<a href="{{ child.url | absolute_url }}">{{ child.title }}</a>{% if child.summary %} - {{ child.summary }}{% endif %}
|
||||||
|
Loading…
Reference in New Issue
Block a user