|
18 | 18 | | group_by: "section" |
19 | 19 | -%} |
20 | 20 |
|
| 21 | +{%- comment -%} |
| 22 | +Separate pages with sections from pages without sections |
| 23 | +{%- endcomment -%} |
| 24 | +{%- assign pages_without_sections = "" | split: "" -%} |
| 25 | +{%- assign pages_with_sections = "" | split: "" -%} |
| 26 | + |
| 27 | +{%- for section in first_level -%} |
| 28 | + {%- if section.name == "" or section.name == nil -%} |
| 29 | + {%- assign pages_without_sections = pages_without_sections | concat: section.items -%} |
| 30 | + {%- else -%} |
| 31 | + {%- assign pages_with_sections = pages_with_sections | push: section -%} |
| 32 | + {%- endif -%} |
| 33 | +{%- endfor -%} |
| 34 | + |
| 35 | +{%- comment -%} |
| 36 | +Sort pages without sections by nav_order |
| 37 | +{%- endcomment -%} |
| 38 | +{%- assign sorted_pages_without_sections = pages_without_sections | sort: 'nav_order' -%} |
| 39 | + |
21 | 40 | {%- assign section_order = site.data.sidebar-section-order.sections -%} |
22 | 41 |
|
23 | 42 | {%- assign ordered_sections = "" | split: "" -%} |
24 | 43 | {%- for section_name in section_order -%} |
25 | | - {%- for section in first_level -%} |
| 44 | + {%- for section in pages_with_sections -%} |
26 | 45 | {%- if section.name == section_name -%} |
27 | 46 | {%- assign ordered_sections = ordered_sections | push: section -%} |
28 | 47 | {%- break -%} |
29 | 48 | {%- endif -%} |
30 | 49 | {%- endfor -%} |
31 | 50 | {%- endfor -%} |
32 | | -+ |
| 51 | + |
33 | 52 | {%- comment -%} |
34 | 53 | Add any sections not in the manual order list at the end |
35 | 54 | {%- endcomment -%} |
36 | | -{%- for section in first_level -%} |
| 55 | +{%- for section in pages_with_sections -%} |
37 | 56 | {%- assign found = false -%} |
38 | 57 | {%- for ordered_section in ordered_sections -%} |
39 | 58 | {%- if section.name == ordered_section.name -%} |
|
55 | 74 | <div class="nhsnotify-pane__side-bar"> |
56 | 75 | <nav class="nhsnotify-side-nav"> |
57 | 76 | <ul class="nhsuk-list nhsnotify-side-nav__list"> |
| 77 | + {%- comment -%} |
| 78 | + First render pages without sections (sorted by nav_order) |
| 79 | + {%- endcomment -%} |
| 80 | + {% for post in sorted_pages_without_sections %} |
| 81 | + {% unless post.has_children %} |
| 82 | + <li class=" |
| 83 | + nhsnotify-side-nav__item |
| 84 | + {% if post.url == page.url %} |
| 85 | + nhsnotify-side-nav__item--current |
| 86 | + {% endif %} |
| 87 | + "> |
| 88 | + <a class="nhsnotify-side-nav__link" href="{{ site.baseurl | append: post.url }}">{{ post.title }}</a> |
| 89 | + </li> |
| 90 | + {% endunless %} |
| 91 | + {% endfor %} |
| 92 | + |
| 93 | + {%- comment -%} |
| 94 | + Then render sections with their pages |
| 95 | + {%- endcomment -%} |
58 | 96 | {% for section in ordered_sections %} |
59 | 97 | {% if section.name != "" %} |
60 | 98 | <li class="nhsuk-u-font-weight-bold nhsnotify-side-nav__list-section">{{ section.name }}</li> |
|
0 commit comments