Forked from budparr/jekyll-collections-prev-next.html
Last active
March 15, 2019 23:29
-
-
Save mmistakes/43a355923921d22cd993 to your computer and use it in GitHub Desktop.
This file contains 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 %} | |
{% for links in document %} | |
{% if links.title == page.title %} | |
{% unless forloop.first %} | |
{% assign prevurl = prev.url %} | |
{% assign prevtitle = prev.title %} | |
{% endunless %} | |
{% unless forloop.last %} | |
{% assign next = document[forloop.index] %} | |
{% assign nexttitle = next.title %} | |
{% assign nexturl = next.url %} | |
{% endunless %} | |
{% endif %} | |
{% assign prev = links %} | |
{% endfor %} | |
{% if prevurl %}<a href="{{ prevurl }}">Previous: {{ prevtitle l}}</a>{% endif %}<br /> | |
{% if nexturl %}<a href="{{ nexturl }}">Next: {{ nexttitle }}</a>{% endif %} | |
<script> | |
/* post pagination keyboard shortcuts */ | |
document.body.onkeyup = function(e){ | |
if (e.keyCode == '37') { window.location = '{{ prevurl }}'; } // left arrow key | |
if (e.keyCode == '39') { window.location = '{{ nexturl }}'; } // right arrow key | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment