mirror of
https://github.com/thangisme/notes.git
synced 2024-11-08 11:37:26 -05:00
83ec553348
Pages with `nav_exclude: true` were included when sorting on `title` or `nav_order`. That could cause build failures when the type of value of the field differs from that on other pages, as reported in https://github.com/pmarsceill/just-the-docs/issues/406. Pages with `nav_exclude: true` or no `title` are never displayed in the navigation, so removing them from `pages_list` cannot break existing sites. This change also allows the removal of some tests in the code. (The indentation of the code should now be adjusted, but that has been deferred, to restrict the size of the diff for review.) For testing, the title of `404.html` has been changed to the number `404`, the page `docs/untitled-test.md` has been added, and `nav_sort_order` has been set to `case_sensitive`. Those updates give build failures with the current version of `_includes/nav.html`, but not after the suggested changes. It will still be possible for build failures to occur due to sorting fields of *non-excluded* pages with differing types of values (e.g., `nav_order`a mixture of numbers and strings). To make the code completely safe will require relatively complicated changes,.
53 lines
3.3 KiB
HTML
53 lines
3.3 KiB
HTML
<ul class="nav-list">
|
|
{%- assign included_pages_list = site.html_pages | where_exp:"item", "item.nav_exclude != true" | where_exp:"item", "item.title != nil" -%}
|
|
{%- assign ordered_pages_list = included_pages_list | where_exp:"item", "item.nav_order != nil" -%}
|
|
{%- assign unordered_pages_list = included_pages_list | where_exp:"item", "item.nav_order == nil" -%}
|
|
{%- if site.nav_sort == 'case_insensitive' -%}
|
|
{%- assign sorted_ordered_pages_list = ordered_pages_list | sort_natural:"nav_order" -%}
|
|
{%- assign sorted_unordered_pages_list = unordered_pages_list | sort_natural:"title" -%}
|
|
{%- else -%}
|
|
{%- assign sorted_ordered_pages_list = ordered_pages_list | sort:"nav_order" -%}
|
|
{%- assign sorted_unordered_pages_list = unordered_pages_list | sort:"title" -%}
|
|
{%- endif -%}
|
|
{%- assign pages_list = sorted_ordered_pages_list | concat: sorted_unordered_pages_list -%}
|
|
{%- for node in pages_list -%}
|
|
{%- if node.parent == nil -%}
|
|
<li class="nav-list-item{% if page.url == node.url or page.parent == node.title or page.grand_parent == node.title %} active{% endif %}">
|
|
{%- if page.parent == node.title or page.grand_parent == node.title -%}
|
|
{%- assign first_level_url = node.url | absolute_url -%}
|
|
{%- endif -%}
|
|
{%- if node.has_children -%}
|
|
<a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a>
|
|
{%- endif -%}
|
|
<a href="{{ node.url | absolute_url }}" class="nav-list-link{% if page.url == node.url %} active{% endif %}">{{ node.title }}</a>
|
|
{%- if node.has_children -%}
|
|
{%- assign children_list = pages_list | where: "parent", node.title -%}
|
|
<ul class="nav-list ">
|
|
{%- for child in children_list -%}
|
|
<li class="nav-list-item {% if page.url == child.url or page.parent == child.title %} active{% endif %}">
|
|
{%- if page.url == child.url or page.parent == child.title -%}
|
|
{%- assign second_level_url = child.url | absolute_url -%}
|
|
{%- endif -%}
|
|
{%- if child.has_children -%}
|
|
<a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a>
|
|
{%- endif -%}
|
|
<a href="{{ child.url | absolute_url }}" class="nav-list-link{% if page.url == child.url %} active{% endif %}">{{ child.title }}</a>
|
|
{%- if child.has_children -%}
|
|
{%- assign grand_children_list = pages_list | where: "parent", child.title | where: "grand_parent", node.title -%}
|
|
<ul class="nav-list">
|
|
{%- for grand_child in grand_children_list -%}
|
|
<li class="nav-list-item {% if page.url == grand_child.url %} active{% endif %}">
|
|
<a href="{{ grand_child.url | absolute_url }}" class="nav-list-link{% if page.url == grand_child.url %} active{% endif %}">{{ grand_child.title }}</a>
|
|
</li>
|
|
{%- endfor -%}
|
|
</ul>
|
|
{%- endif -%}
|
|
</li>
|
|
{%- endfor -%}
|
|
</ul>
|
|
{%- endif -%}
|
|
</li>
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
</ul>
|