Forked from budparr/jekyll-collections-prev-next.html
Created
September 19, 2016 09:56
-
-
Save fluffybeing/cfef30eaea6946f24e8013bfcf7ba249 to your computer and use it in GitHub Desktop.
Previous Next Links for Jekyll Collections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% capture the_collection %}{{page.collection}}{% endcapture %} | |
{% if page.collection %} | |
{% assign document = site[the_collection] %} | |
{% endif %} | |
<h1>TITLE: {{ page.title }}</h1> | |
{% for links in document %} | |
{% if links.title == page.title %} | |
{% unless forloop.first %} | |
{% assign prevurl = prev.url %} | |
{% endunless %} | |
{% unless forloop.last %} | |
{% assign next = document[forloop.index] %} | |
{% assign nexturl = next.url %} | |
{% endunless %} | |
{% endif %} | |
{% assign prev = links %} | |
{% endfor %} | |
<script> | |
document.body.onkeyup = function(e){ | |
if (e.keyCode == '37') { window.location = '{{prevurl}}'; } | |
if (e.keyCode == '39') { window.location = '{{nexturl}}'; } | |
}; | |
</script> | |
{% if prevurl %}<a href="{{prevurl}}" class="prev">PREV {{prevurl}}</a>{% endif %}<br /> | |
{% if nexturl %}<a href="{{nexturl}}" class="nxt">Next {{nexturl}}</a>{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment