2019-07-22 07:33:17 +00:00
|
|
|
<ul class="nav-list">
|
2020-08-11 16:25:58 +00:00
|
|
|
{%- assign included_pages = site.html_pages
|
|
|
|
| where_exp:"item", "item.nav_exclude != true"
|
|
|
|
| where_exp:"item", "item.title != nil" -%}
|
|
|
|
|
|
|
|
{%- comment -%}
|
|
|
|
A nav_order value can be a number or a string.
|
|
|
|
Numbers are sorted by their values, before strings.
|
|
|
|
An omitted nav_order value is equivalent to the title value,
|
|
|
|
except that a numerical title value is treated as a string.
|
|
|
|
The case-sensitivity of string sorting is determined by site.nav_sort.
|
|
|
|
{%- endcomment -%}
|
|
|
|
|
|
|
|
{%- assign string_ordered_pages = included_pages
|
|
|
|
| where_exp:"item", "item.nav_order == nil" -%}
|
|
|
|
{%- assign nav_ordered_pages = included_pages
|
|
|
|
| where_exp:"item", "item.nav_order != nil" -%}
|
|
|
|
|
|
|
|
{%- comment -%}
|
|
|
|
The nav_ordered_pages have to be added to number_ordered_pages and
|
|
|
|
string_ordered_pages, depending on the nav_order value.
|
|
|
|
The first character of jsonify is `"` only for strings.
|
|
|
|
{%- endcomment -%}
|
|
|
|
{%- assign nav_ordered_groups = nav_ordered_pages
|
|
|
|
| group_by_exp:"item", "item.nav_order | jsonify | slice: 0" -%}
|
|
|
|
{%- assign number_ordered_pages = "" | split:"X" -%}
|
|
|
|
{%- for group in nav_ordered_groups -%}
|
|
|
|
{%- if group.name == '"' -%}
|
|
|
|
{%- assign string_ordered_pages = string_ordered_pages | concat: group.items -%}
|
|
|
|
{%- else -%}
|
|
|
|
{%- assign number_ordered_pages = number_ordered_pages | concat: group.items -%}
|
|
|
|
{%- endif -%}
|
|
|
|
{%- endfor -%}
|
|
|
|
|
|
|
|
{%- assign sorted_number_ordered_pages = number_ordered_pages | sort:"nav_order" -%}
|
|
|
|
|
|
|
|
{%- comment -%}
|
|
|
|
The string_ordered_pages have to be sorted by nav_order, and otherwise title.
|
|
|
|
After grouping them by those values, the groups are sorted, then the items
|
|
|
|
of each group are concatenated.
|
|
|
|
{%- endcomment -%}
|
|
|
|
{%- assign string_ordered_groups = string_ordered_pages
|
|
|
|
| group_by_exp:"item", "item.nav_order | default: item.title | string" -%}
|
2020-06-15 19:23:03 +00:00
|
|
|
{%- if site.nav_sort == 'case_insensitive' -%}
|
2020-08-11 16:25:58 +00:00
|
|
|
{%- assign sorted_string_ordered_groups = string_ordered_groups | sort_natural:"name" -%}
|
2020-06-15 19:23:03 +00:00
|
|
|
{%- else -%}
|
2020-08-11 16:25:58 +00:00
|
|
|
{%- assign sorted_string_ordered_groups = string_ordered_groups | sort:"name" -%}
|
2020-06-15 19:23:03 +00:00
|
|
|
{%- endif -%}
|
2020-08-11 16:25:58 +00:00
|
|
|
{%- assign sorted_string_ordered_pages = "" | split:"X" -%}
|
|
|
|
{%- for group in sorted_string_ordered_groups -%}
|
|
|
|
{%- assign sorted_string_ordered_pages = sorted_string_ordered_pages | concat: group.items -%}
|
|
|
|
{%- endfor -%}
|
|
|
|
|
|
|
|
{%- assign pages_list = sorted_number_ordered_pages | concat: sorted_string_ordered_pages -%}
|
|
|
|
|
2019-07-21 12:36:51 +00:00
|
|
|
{%- for node in pages_list -%}
|
Ensure pages with nav_exclude are ignored by navigation
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,.
2020-08-10 13:58:42 +00:00
|
|
|
{%- if node.parent == nil -%}
|
2019-07-22 07:33:17 +00:00
|
|
|
<li class="nav-list-item{% if page.url == node.url or page.parent == node.title or page.grand_parent == node.title %} active{% endif %}">
|
2019-07-21 12:36:51 +00:00
|
|
|
{%- if page.parent == node.title or page.grand_parent == node.title -%}
|
|
|
|
{%- assign first_level_url = node.url | absolute_url -%}
|
|
|
|
{%- endif -%}
|
2019-08-10 18:53:59 +00:00
|
|
|
{%- if node.has_children -%}
|
2019-12-01 14:51:48 +00:00
|
|
|
<a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a>
|
2019-08-10 18:53:59 +00:00
|
|
|
{%- endif -%}
|
2019-07-22 07:33:17 +00:00
|
|
|
<a href="{{ node.url | absolute_url }}" class="nav-list-link{% if page.url == node.url %} active{% endif %}">{{ node.title }}</a>
|
2019-07-21 12:36:51 +00:00
|
|
|
{%- if node.has_children -%}
|
2020-06-15 19:23:03 +00:00
|
|
|
{%- assign children_list = pages_list | where: "parent", node.title -%}
|
|
|
|
<ul class="nav-list ">
|
2019-07-21 12:36:51 +00:00
|
|
|
{%- for child in children_list -%}
|
2020-06-15 19:23:03 +00:00
|
|
|
<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 -%}
|
2020-06-15 20:06:16 +00:00
|
|
|
<a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a>
|
2020-06-15 19:23:03 +00:00
|
|
|
{%- 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>
|
2019-07-21 12:36:51 +00:00
|
|
|
{%- endfor -%}
|
|
|
|
</ul>
|
|
|
|
{%- endif -%}
|
|
|
|
</li>
|
|
|
|
{%- endif -%}
|
|
|
|
{%- endfor -%}
|
|
|
|
</ul>
|