{% comment %} Lets turn our yaml into a structured list of documents without titles. {% endcomment %} {% assign docs = site.data.docs | map: 'docs' %} {% capture document_array_string %} {% for doc in docs %} {% assign last_last = forloop.last %} {% for title in doc %} {{title}}{% unless forloop.last and last_last %},{% endunless %} {% endfor %} {% endfor %} {% endcapture %} {% assign document_array = document_array_string | strip_newlines | split: ',' %} {% comment %} Because this is built for every page, lets find where we are in the document list by comparing url strings. Then if there's something previous or next, lets build links to it. Note: When arrays are accessed directly, they are zero based. {% endcomment %} {% for document in document_array %} {% assign document_url = document | prepend:"/docs/" | append:"/" %} {% if document_url == page.url %}
{% if forloop.first %} Back {% else %} {% assign previous = forloop.index0 | minus: 1 %} {% assign previous_page = document_array[previous] | prepend:"/docs/" | append:"/" %} {% endif %}
{% if forloop.last %} Next {% else %} {% assign next = forloop.index0 | plus: 1 %} {% assign next_page = document_array[next] | prepend:"/docs/" | append:"/" %} {% endif %}
{% break %} {% endif %} {% endfor %}