-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprev_next.html
More file actions
44 lines (44 loc) · 1.91 KB
/
prev_next.html
File metadata and controls
44 lines (44 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{%- comment -%}
Renders previous/next navigation for the linear reading path of the manual.
Used by _layouts/linear.html. Sequence is defined in _data/linear_sequence.yml.
Finds the current page by matching page.path against entries in the sequence,
then resolves neighbors to real page objects so we get URLs and titles for free.
{%- endcomment -%}
{%- assign seq = site.data.linear_sequence -%}
{%- assign current_index = -1 -%}
{%- for entry in seq -%}
{%- if entry == page.path -%}
{%- assign current_index = forloop.index0 -%}
{%- endif -%}
{%- endfor -%}
{%- if current_index >= 0 -%}
{%- assign prev_index = current_index | minus: 1 -%}
{%- assign next_index = current_index | plus: 1 -%}
{%- assign last_index = seq.size | minus: 1 -%}
{%- assign prev_path = "" -%}
{%- assign next_path = "" -%}
{%- for entry in seq -%}
{%- if forloop.index0 == prev_index -%}{%- assign prev_path = entry -%}{%- endif -%}
{%- if forloop.index0 == next_index -%}{%- assign next_path = entry -%}{%- endif -%}
{%- endfor -%}
{%- assign prev_page = site.pages | where: "path", prev_path | first -%}
{%- assign next_page = site.pages | where: "path", next_path | first -%}
<nav class="prev-next-nav" aria-label="Reading sequence navigation">
<div class="prev-next-nav__prev">
{%- if current_index > 0 and prev_page -%}
<a href="{{ prev_page.url | relative_url }}">
<span class="prev-next-nav__label">← Previous</span>
<span class="prev-next-nav__title">{{ prev_page.title }}</span>
</a>
{%- endif -%}
</div>
<div class="prev-next-nav__next">
{%- if current_index < last_index and next_page -%}
<a href="{{ next_page.url | relative_url }}">
<span class="prev-next-nav__label">Next →</span>
<span class="prev-next-nav__title">{{ next_page.title }}</span>
</a>
{%- endif -%}
</div>
</nav>
{%- endif -%}