1+ {%- comment -%}
2+ This file renders a single sidebar nav item, which is a list element defined
3+ in `_data/nav/< product _version > .yml`.
4+
5+ The nav item is passed in as `include.item` and can take one of three shapes:
6+
7+ - `items:` only -> collapsible topic header (just expands/collapses)
8+ - `link:` only -> leaf item; display link to page content
9+ - `link:` and `items:` -> collapsible header AND has its own page content
10+ (e.g., OpenBolt's "Plans")
11+
12+ Nested levels are handled by recursing into `include.item.items`.
13+ {%- endcomment -%}
114{% if include.item.items %}
215 {% assign nav_next_level = include.level | plus: 1 %}
316
17+ {%- comment -%}
18+ It's necessary to pre-render all child items before this item,
19+ because we'll need to peek at their formatting to decide our own.
20+ {%- endcomment -%}
421 {% capture nav_children %}
522 {% for child in include.item.items %}
623 {% include nav-item.html item=child level=nav_next_level %}
724 {% endfor %}
825 {% endcapture %}
926
27+ {%- comment -%}
28+ Compute our item's absolute URL/`nav_item_url`:
29+ - Absolute links ("/openvox-server/latest/http_api_index.html") used as-is
30+ - Relative links ("plans.html") prepend `nav_base` ("/openbolt/latest/")
31+
32+ It's important to compute this AFTER the recursive children capture above:
33+ Liquid's `assign` (below) leaks between includes + theirs would whack ours!
34+ {%- endcomment -%}
35+ {% if include.item.link %}
36+ {% assign nav_link_first_char = include.item.link | slice: 0 %}
37+ {% if nav_link_first_char == '/' %}
38+ {% assign nav_item_url = include.item.link %}
39+ {% else %}
40+ {% assign nav_item_url = include.item.link | prepend: nav_base %}
41+ {% endif %}
42+ {% endif %}
43+
44+ {%- comment -%}
45+ Peek at buffered markup; if any are `is-active`, our formatting must change
46+ {%- endcomment -%}
1047 {% assign nav_has_active = false %}
1148 {% if nav_children contains 'is-active' %}
1249 {% assign nav_has_active = true %}
1350 {% endif %}
51+ {% if include.item.link and nav_item_url == page.url %}
52+ {% assign nav_has_active = true %}
53+ {% endif %}
1454
1555 < div class ="group no-transition ">
1656 < section class ="VPSidebarItem level-{{ include.level }} collapsible{% if nav_has_active %} has-active{% endif %} " data-vp-sidebar-group >
17- < div class ="item " role ="button " tabindex ="0 ">
57+ < div class ="item "{% unless include.item.link %} role ="button " tabindex ="0 "{% endunless %} >
1858 < div class ="indicator "> </ div >
19- < h2 class ="text "> {{ include.item.text }}</ h2 >
59+ {% if include.item.link %}
60+ < a class ="VPLink link link{% if nav_item_url == page.url %} is-active{% endif %} " href ="{{ nav_item_url }} " data-vp-sidebar-link data-turbo ="true " data-turbo-frame ="vp-content-frame " data-turbo-action ="advance ">
61+ < h2 class ="text "> {{ include.item.text }}</ h2 >
62+ </ a >
63+ {% else %}
64+ < h2 class ="text "> {{ include.item.text }}</ h2 >
65+ {% endif %}
2066 < div class ="caret " role ="button " aria-label ="toggle section " tabindex ="0 ">
2167 < span class ="vpi-chevron-right caret-icon "> </ span >
2268 </ div >
@@ -28,10 +74,6 @@ <h2 class="text">{{ include.item.text }}</h2>
2874 </ section >
2975 </ div >
3076{% elsif include.item.link %}
31- {%- comment -%}
32- Links starting with '/' are already absolute site paths. Prepending nav_base (which also
33- starts with '/') would produce a broken double-prefix like /openvox/latest//other/page.html.
34- {%- endcomment -%}
3577 {% assign nav_link_first_char = include.item.link | slice: 0 %}
3678 {% if nav_link_first_char == '/' %}
3779 {% assign nav_item_url = include.item.link %}
0 commit comments