1+ <!-- Render navigation link status -->
2+ {% macro render_status(nav_item, type) %}
3+ {% set class = "md-status md-status--" ~ type %}
4+
5+ <!-- Render icon with title (or tooltip), if given -->
6+ {% if config.extra.status and config.extra.status[type] %}
7+ < span
8+ class ="{{ class }} "
9+ title ="{{ config.extra.status[type] }} "
10+ >
11+ </ span >
12+
13+ <!-- Render icon only -->
14+ {% else %}
15+ < span class ="{{ class }} "> </ span >
16+ {% endif %}
17+ {% endmacro %}
18+
19+ <!-- Render navigation link content -->
20+ {% macro render_content(nav_item, ref = nav_item) %}
21+
22+ <!-- Navigation link icon -->
23+ {% if nav_item.is_page and nav_item.meta.icon %}
24+ {% include ".icons/" ~ nav_item.meta.icon ~ ".svg" %}
25+ {% endif %}
26+
27+ <!-- Navigation link title -->
28+ < span class ="md-ellipsis ">
29+ {{ ref.title }}
30+ </ span >
31+
32+ <!-- Navigation link status -->
33+ {% if nav_item.is_page and nav_item.meta.status %}
34+ {{ render_status(nav_item, nav_item.meta.status) }}
35+ {% endif %}
36+ {% endmacro %}
37+
38+ <!-- Render navigation item (pruned) -->
39+ {% macro render_pruned(nav_item, ref = nav_item) %}
40+ {% set first = nav_item.children | first %}
41+
42+ <!-- Recurse, if the first item has further nested items -->
43+ {% if first and first.children %}
44+ {{ render_pruned(first, ref) }}
45+
46+ <!-- Navigation link -->
47+ {% else %}
48+ < a href ="{{ first.url | url }} " class ="md-nav__link ">
49+ {{ render_content(ref) }}
50+
51+ <!-- Only render toggle if there's at least one nested item -->
52+ {% if nav_item.children | length > 0 %}
53+ < span class ="md-nav__icon md-icon "> </ span >
54+ {% endif %}
55+ </ a >
56+ {% endif %}
57+ {% endmacro %}
58+
59+ <!-- Render navigation item -->
60+ {% macro render(nav_item, path, level) %}
61+
62+ <!-- Determine classes -->
63+ {% set class = "md-nav__item" %}
64+ {% if nav_item.active %}
65+ {% set class = class ~ " md-nav__item--active" %}
66+ {% endif %}
67+
68+ <!-- Determine active page for paginated views -->
69+ {% if nav_item.pages %}
70+ {% if page in nav_item.pages %}
71+ {% set nav_item = page %}
72+ {% endif %}
73+ {% endif %}
74+
75+ <!-- Navigation item with nested items -->
76+ {% if nav_item.children %}
77+
78+ <!-- Determine all nested items that are index pages -->
79+ {% set indexes = [] %}
80+ {% if "navigation.indexes" in features %}
81+ {% for nav_item in nav_item.children %}
82+ {% if nav_item.is_index and not index is defined %}
83+ {% set _ = indexes.append(nav_item) %}
84+ {% endif %}
85+ {% endfor %}
86+ {% endif %}
87+
88+ <!-- Navigation tabs -->
89+ {% if "navigation.tabs" in features %}
90+
91+ <!-- Render 1st level active item as section -->
92+ {% if level == 1 and nav_item.active %}
93+ {% set class = class ~ " md-nav__item--section" %}
94+ {% set is_section = true %}
95+ {% endif %}
96+
97+ <!-- Navigation tabs + sections -->
98+ {% if "navigation.sections" in features %}
99+
100+ <!-- Render 2nd level items with nested items as sections -->
101+ {% if level == 2 and nav_item.parent.active %}
102+ {% set class = class ~ " md-nav__item--section" %}
103+ {% set is_section = true %}
104+ {% endif %}
105+ {% endif %}
106+
107+ <!-- Navigation sections -->
108+ {% elif "navigation.sections" in features %}
109+
110+ <!-- Render 1st level items with nested items as sections -->
111+ {% if level == 1 %}
112+ {% set class = class ~ " md-nav__item--section" %}
113+ {% set is_section = true %}
114+ {% endif %}
115+ {% endif %}
116+
117+ <!-- Navigation pruning -->
118+ {% if "navigation.prune" in features %}
119+
120+ <!-- Prune item if it is not a section and not active -->
121+ {% if not is_section and not nav_item.active %}
122+ {% set class = class ~ " md-nav__item--pruned" %}
123+ {% set is_pruned = true %}
124+ {% endif %}
125+ {% endif %}
126+
127+ <!-- Nested navigation item -->
128+ < li class ="{{ class }} md-nav__item--nested ">
129+ {% if not is_pruned %}
130+ {% set checked = "checked" if nav_item.active %}
131+
132+ <!-- Determine checked and indeterminate state -->
133+ {% if "navigation.expand" in features and not checked %}
134+ {% set indeterminate = "md-toggle--indeterminate" %}
135+ {% endif %}
136+
137+ <!-- Active checkbox expands items contained within nested section -->
138+ < input
139+ class ="md-nav__toggle md-toggle {{ indeterminate }} "
140+ type ="checkbox "
141+ id ="{{ path }} "
142+ {{ checked }}
143+ />
144+
145+ <!-- Toggle to expand nested items -->
146+ {% if not indexes %}
147+ {% set tabindex = "0" if not is_section %}
148+ < label
149+ class ="md-nav__link "
150+ for ="{{ path }} "
151+ id ="{{ path }}_label "
152+ tabindex ="{{ tabindex }} "
153+ >
154+ {{ render_content(nav_item) }}
155+ < span class ="md-nav__icon md-icon "> </ span >
156+ </ label >
157+
158+ <!-- Toggle to expand nested items with link to index page -->
159+ {% else %}
160+ {% set index = indexes | first %}
161+ {% set class = "md-nav__link--active" if index == page %}
162+ < div class ="md-nav__link md-nav__container ">
163+ < a
164+ href ="{{ index.url | url }} "
165+ class ="md-nav__link {{ class }} "
166+ >
167+ {{ render_content(index, nav_item) }}
168+ </ a >
169+
170+ <!-- Only render toggle if there's at least one more page -->
171+ {% if nav_item.children | length > 1 %}
172+ {% set tabindex = "0" if not is_section %}
173+ < label
174+ class ="md-nav__link {{ class }} "
175+ for ="{{ path }} "
176+ id ="{{ path }}_label "
177+ tabindex ="{{ tabindex }} "
178+ >
179+ < span class ="md-nav__icon md-icon "> </ span >
180+ </ label >
181+ {% endif %}
182+ </ div >
183+ {% endif %}
184+
185+ <!-- Nested navigation -->
186+ < nav
187+ class ="md-nav "
188+ data-md-level ="{{ level }} "
189+ aria-labelledby ="{{ path }}_label "
190+ aria-expanded ="{{ nav_item.active | tojson }} "
191+ >
192+ < label class ="md-nav__title " for ="{{ path }} ">
193+ < span class ="md-nav__icon md-icon "> </ span >
194+ {{ nav_item.title }}
195+ </ label >
196+ < ul class ="md-nav__list " data-md-scrollfix >
197+
198+ <!-- Nested navigation item -->
199+ {% for nav_item in nav_item.children %}
200+ {% if not indexes or nav_item != indexes | first %}
201+ {{ render(nav_item, path ~ "_" ~ loop.index, level + 1) }}
202+ {% endif %}
203+ {% endfor %}
204+ </ ul >
205+ </ nav >
206+
207+ <!-- Pruned navigation item -->
208+ {% else %}
209+ {{ render_pruned(nav_item) }}
210+ {% endif %}
211+ </ li >
212+
213+ <!-- Currently active page -->
214+ {% elif nav_item == page %}
215+ < li class ="{{ class }} ">
216+ {% set toc = page.toc %}
217+
218+ <!-- State toggle -->
219+ < input
220+ class ="md-nav__toggle md-toggle "
221+ type ="checkbox "
222+ id ="__toc "
223+ />
224+
225+ <!-- Hack: see partials/toc.html for more information -->
226+ {% set first = toc | first %}
227+ {% if first and first.level == 1 %}
228+ {% set toc = first.children %}
229+ {% endif %}
230+
231+ <!-- Navigation link to table of contents -->
232+ {% if toc %}
233+ < label class ="md-nav__link md-nav__link--active " for ="__toc ">
234+ {{ render_content(nav_item) }}
235+ < span class ="md-nav__icon md-icon "> </ span >
236+ </ label >
237+ {% endif %}
238+ < a
239+ href ="{{ nav_item.url | url }} "
240+ class ="md-nav__link md-nav__link--active "
241+ >
242+ {{ render_content(nav_item) }}
243+ </ a >
244+
245+ <!-- Table of contents -->
246+ {% if toc %}
247+ {% include "partials/toc.html" %}
248+ {% endif %}
249+ </ li >
250+
251+ <!-- Navigation item -->
252+ {% else %}
253+ < li class ="{{ class }} ">
254+ < a href ="{{ nav_item.url | url }} " class ="md-nav__link ">
255+ {{ render_content(nav_item) }}
256+ </ a >
257+ </ li >
258+ {% endif %}
259+ {% endmacro %}
0 commit comments