{% 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>