Created
July 11, 2018 12:48
-
-
Save tvdsluijs/49dd4523bb919e85c24fa32e3834b719 to your computer and use it in GitHub Desktop.
Better pagination for Jekyll on Github pages, also see :
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
{% if paginator.total_pages > 1 %} | |
<div class="pagination"> | |
{% if paginator.previous_page %} | |
<a class="ml-1 mr-2" href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">« {{site.str_previous_page}}</a> | |
{% else %} | |
<span>« {{site.str_previous_page}}</span> | |
{% endif %} | |
{% assign page_start = paginator.page | minus: site.pagination_nr %} | |
{% assign page_end = paginator.page | plus: site.pagination_nr %} | |
{% for page in (page_start..page_end) %} | |
{% if page < 1 %} | |
<!-- do freaking nothing --> | |
{% elsif page == paginator.page %} | |
<span class="ml-1 mr-1">{{ page }}</span> | |
{% elsif page == 1 %} | |
<a class="ml-1 mr-2" href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">{{ page }}</a> | |
{% else %} | |
<a class="ml-1 mr-2" href="{{ site.paginate_path | prepend: site.baseurl | replace: '//', '/' | replace: ':num', page }}">{{ page }}</a> | |
{% endif %} | |
{% endfor %} | |
{% if paginator.next_page %} | |
<a class="ml-1 mr-2" href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">{{site.str_next_page}} »</a> | |
{% else %} | |
<span>{{site.str_next_page}} »</span> | |
{% endif %} | |
</div> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this!
I suggest adding these 2 lines of code after the
{% if page < 1 %}
, because you will get a higher number of pages than you actually have.So the whole for loop would be: