Skip to content

Commit 2582146

Browse files
fix(navigation): restore original sidebar order for Features section (#117)
- Separate pages without sections from pages with sections - Display pages without sections at top, sorted by nav_order - Render sections below in configured order from sidebar-section-order.yml - Fixes issue where Roadmap and Security appeared at bottom instead of top - Maintains logical information hierarchy for better UX
1 parent dec6565 commit 2582146

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

docs/_layouts/page.html

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,30 @@
1818
| group_by: "section"
1919
-%}
2020

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+
2140
{%- assign section_order = site.data.sidebar-section-order.sections -%}
2241

2342
{%- assign ordered_sections = "" | split: "" -%}
2443
{%- for section_name in section_order -%}
25-
{%- for section in first_level -%}
44+
{%- for section in pages_with_sections -%}
2645
{%- if section.name == section_name -%}
2746
{%- assign ordered_sections = ordered_sections | push: section -%}
2847
{%- break -%}
@@ -33,7 +52,7 @@
3352
{%- comment -%}
3453
Add any sections not in the manual order list at the end
3554
{%- endcomment -%}
36-
{%- for section in first_level -%}
55+
{%- for section in pages_with_sections -%}
3756
{%- assign found = false -%}
3857
{%- for ordered_section in ordered_sections -%}
3958
{%- if section.name == ordered_section.name -%}
@@ -55,6 +74,25 @@
5574
<div class="nhsnotify-pane__side-bar">
5675
<nav class="nhsnotify-side-nav">
5776
<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 -%}
5896
{% for section in ordered_sections %}
5997
{% if section.name != "" %}
6098
<li class="nhsuk-u-font-weight-bold nhsnotify-side-nav__list-section">{{ section.name }}</li>

0 commit comments

Comments
 (0)