Skip to content

Commit e4fbf33

Browse files
author
Claire Nord
committed
layouts lecture: add previous/next arrows
1 parent 2d88a18 commit e4fbf33

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

_layouts/lecture.html

+41
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,47 @@ <h1 class="title">{{ page.title }}{% if page.subtitle %} <span class="subtitle">
77

88
{{ content }}
99

10+
{% comment %}
11+
From https://talk.jekyllrb.com/t/previous-and-next-links-with-a-collections/3171
12+
{% endcomment %}
13+
{% assign items_raw = site.lectures %}
14+
{% assign items = items_raw | sort: 'number' | reverse %}
15+
16+
{% if items.size > 1 %}
17+
{% comment %}
18+
Store the index position of the matching items
19+
{% endcomment %}
20+
{% for item in items %}
21+
{% if item.title == page.title %}
22+
{% assign item_index = forloop.index %}
23+
{% endif %}
24+
{% endfor %}
25+
26+
{% assign prev_index = item_index | plus: 1 %}
27+
{% assign next_index = item_index | minus: 1 %}
28+
29+
{% for item in items %}
30+
{% if forloop.index == prev_index %}
31+
{% assign prev = item %}
32+
{% endif %}
33+
{% if forloop.index == next_index %}
34+
{% assign next = item %}
35+
{% endif %}
36+
{% endfor %}
37+
38+
<p>
39+
{% if prev %}
40+
<a href="{{ site.baseurl}}{{ prev.url }}" class="prev" title="{{ prev.title }}">&lt; Previous</a>
41+
{% endif %}
42+
{% if prev and next %}
43+
<span> | </span>
44+
{% endif %}
45+
{% if next %}
46+
<a href="{{ site.baseurl }}{{ next.url }}" class="next" title="{{ next.title }}">Next &gt;</a>
47+
{% endif %}
48+
</p>
49+
{% endif %}
50+
1051
<hr>
1152

1253
<div class="small center">

0 commit comments

Comments
 (0)