|
1 |
| -<nav role="navigation" aria-label="Main navigation"> |
2 |
| - <ul class="navigation-list"> |
3 |
| - {%- assign pages_list = site.html_pages | sort:"nav_order" -%} |
4 |
| - {%- for node in pages_list -%} |
5 |
| - {%- unless node.nav_exclude or node.layout == "redirect" -%} |
| 1 | +<ul class="nav-list"> |
| 2 | + {%- assign titled_pages = include.pages |
| 3 | + | where_exp:"item", "item.title != nil" -%} |
| 4 | + |
| 5 | + {%- comment -%} |
| 6 | + The values of `title` and `nav_order` can be numbers or strings. |
| 7 | + Jekyll gives build failures when sorting on mixtures of different types, |
| 8 | + so numbers and strings need to be sorted separately. |
| 9 | + |
| 10 | + Here, numbers are sorted by their values, and come before all strings. |
| 11 | + An omitted `nav_order` value is equivalent to the page's `title` value |
| 12 | + (except that a numerical `title` value is treated as a string). |
| 13 | + |
| 14 | + The case-sensitivity of string sorting is determined by `site.nav_sort`. |
| 15 | + {%- endcomment -%} |
| 16 | + |
| 17 | + {%- assign string_ordered_pages = titled_pages |
| 18 | + | where_exp:"item", "item.nav_order == nil" -%} |
| 19 | + {%- assign nav_ordered_pages = titled_pages |
| 20 | + | where_exp:"item", "item.nav_order != nil" -%} |
| 21 | + |
| 22 | + {%- comment -%} |
| 23 | + The nav_ordered_pages have to be added to number_ordered_pages and |
| 24 | + string_ordered_pages, depending on the nav_order value. |
| 25 | + The first character of the jsonify result is `"` only for strings. |
| 26 | + {%- endcomment -%} |
| 27 | + {%- assign nav_ordered_groups = nav_ordered_pages |
| 28 | + | group_by_exp:"item", "item.nav_order | jsonify | slice: 0" -%} |
| 29 | + {%- assign number_ordered_pages = "" | split:"X" -%} |
| 30 | + {%- for group in nav_ordered_groups -%} |
| 31 | + {%- if group.name == '"' -%} |
| 32 | + {%- assign string_ordered_pages = string_ordered_pages | concat: group.items -%} |
| 33 | + {%- else -%} |
| 34 | + {%- assign number_ordered_pages = number_ordered_pages | concat: group.items -%} |
| 35 | + {%- endif -%} |
| 36 | + {%- endfor -%} |
| 37 | + |
| 38 | + {%- assign sorted_number_ordered_pages = number_ordered_pages | sort:"nav_order" -%} |
| 39 | + |
| 40 | + {%- comment -%} |
| 41 | + The string_ordered_pages have to be sorted by nav_order, and otherwise title |
| 42 | + (where appending the empty string to a numeric title converts it to a string). |
| 43 | + After grouping them by those values, the groups are sorted, then the items |
| 44 | + of each group are concatenated. |
| 45 | + {%- endcomment -%} |
| 46 | + {%- assign string_ordered_groups = string_ordered_pages |
| 47 | + | group_by_exp:"item", "item.nav_order | default: item.title | append:''" -%} |
| 48 | + {%- if site.nav_sort == 'case_insensitive' -%} |
| 49 | + {%- assign sorted_string_ordered_groups = string_ordered_groups | sort_natural:"name" -%} |
| 50 | + {%- else -%} |
| 51 | + {%- assign sorted_string_ordered_groups = string_ordered_groups | sort:"name" -%} |
| 52 | + {%- endif -%} |
| 53 | + {%- assign sorted_string_ordered_pages = "" | split:"X" -%} |
| 54 | + {%- for group in sorted_string_ordered_groups -%} |
| 55 | + {%- assign sorted_string_ordered_pages = sorted_string_ordered_pages | concat: group.items -%} |
| 56 | + {%- endfor -%} |
| 57 | + |
| 58 | + {%- assign pages_list = sorted_number_ordered_pages | concat: sorted_string_ordered_pages -%} |
| 59 | + |
| 60 | + {%- for node in pages_list -%} |
6 | 61 | {%- if node.parent == nil -%}
|
7 |
| - <li |
8 |
| - class="navigation-list-item{% if page.url == node.url or page.parent == node.title or page.grand_parent == node.title %} active{% endif %}"> |
9 |
| - {%- if page.parent == node.title or page.grand_parent == node.title -%} |
10 |
| - {%- assign first_level_url = node.url | absolute_url -%} |
11 |
| - {%- endif -%} |
12 |
| - <a href="{{ node.url | absolute_url }}" |
13 |
| - class="navigation-list-link{% if page.url == node.url %} active{% endif %}">{{ node.title }}</a> |
14 |
| - {%- if node.has_children -%} |
15 |
| - {%- assign children_list = site.html_pages | where: "parent", node.title | sort:"nav_order" -%} |
16 |
| - <ul class="navigation-list-child-list "> |
17 |
| - {%- for child in children_list -%} |
18 |
| - <li class="navigation-list-item {% if page.url == child.url or page.parent == child.title %} active{% endif %}"> |
19 |
| - {%- if page.url == child.url or page.parent == child.title -%} |
20 |
| - {%- assign second_level_url = child.url | absolute_url -%} |
21 |
| - {%- endif -%} |
22 |
| - <a href="{{ child.url | absolute_url }}" |
23 |
| - class="navigation-list-link{% if page.url == child.url %} active{% endif %}">{{ child.title }}</a> |
24 |
| - {%- if child.has_children -%} |
25 |
| - {%- assign grand_children_list = site.html_pages | where: "parent", child.title | sort:"nav_order" -%} |
26 |
| - <ul class="navigation-list-child-list"> |
27 |
| - {%- for grand_child in grand_children_list -%} |
28 |
| - <li class="navigation-list-item {% if page.url == grand_child.url %} active{% endif %}"> |
29 |
| - <a href="{{ grand_child.url | absolute_url }}" |
30 |
| - class="navigation-list-link{% if page.url == grand_child.url %} active{% endif %}">{{ grand_child.title }}</a> |
| 62 | + {%- unless node.nav_exclude -%} |
| 63 | + <li class="nav-list-item{% if page.url == node.url or page.parent == node.title or page.grand_parent == node.title %} active{% endif %}"> |
| 64 | + {%- if node.has_children -%} |
| 65 | + <a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a> |
| 66 | + {%- endif -%} |
| 67 | + <a href="{{ node.url | absolute_url }}" class="nav-list-link{% if page.url == node.url %} active{% endif %}">{{ node.title }}</a> |
| 68 | + {%- if node.has_children -%} |
| 69 | + {%- assign children_list = pages_list | where: "parent", node.title -%} |
| 70 | + <ul class="nav-list "> |
| 71 | + {%- for child in children_list -%} |
| 72 | + {%- unless child.nav_exclude -%} |
| 73 | + <li class="nav-list-item {% if page.url == child.url or page.parent == child.title %} active{% endif %}"> |
| 74 | + {%- if child.has_children -%} |
| 75 | + <a href="#" class="nav-list-expander"><svg viewBox="0 0 24 24"><use xlink:href="#svg-arrow-right"></use></svg></a> |
| 76 | + {%- endif -%} |
| 77 | + <a href="{{ child.url | absolute_url }}" class="nav-list-link{% if page.url == child.url %} active{% endif %}">{{ child.title }}</a> |
| 78 | + {%- if child.has_children -%} |
| 79 | + {%- assign grand_children_list = pages_list | where: "parent", child.title | where: "grand_parent", node.title -%} |
| 80 | + <ul class="nav-list"> |
| 81 | + {%- for grand_child in grand_children_list -%} |
| 82 | + {%- unless grand_child.nav_exclude -%} |
| 83 | + <li class="nav-list-item {% if page.url == grand_child.url %} active{% endif %}"> |
| 84 | + <a href="{{ grand_child.url | absolute_url }}" class="nav-list-link{% if page.url == grand_child.url %} active{% endif %}">{{ grand_child.title }}</a> |
| 85 | + </li> |
| 86 | + {%- endunless -%} |
| 87 | + {%- endfor -%} |
| 88 | + </ul> |
| 89 | + {%- endif -%} |
31 | 90 | </li>
|
32 |
| - {%- endfor -%} |
| 91 | + {%- endunless -%} |
| 92 | + {%- endfor -%} |
33 | 93 | </ul>
|
34 |
| - {%- endif -%} |
35 |
| - </li> |
36 |
| - {%- endfor -%} |
37 |
| - </ul> |
38 |
| - {%- endif -%} |
39 |
| - </li> |
| 94 | + {%- endif -%} |
| 95 | + </li> |
| 96 | + {%- endunless -%} |
40 | 97 | {%- endif -%}
|
41 |
| - {%- endunless -%} |
42 |
| - {%- endfor -%} |
43 |
| - </ul> |
44 |
| -</nav> |
| 98 | + {%- endfor -%} |
| 99 | +</ul> |
0 commit comments