|
| 1 | +{% if paginator.total_pages > 1 %} |
| 2 | +<nav class="pagination"> |
| 3 | + {% assign first_page_path = paginator.first_page_path | default: site.paginate_path | replace: 'page:num', '' | replace: '//', '/' | relative_url %} |
| 4 | + <ul> |
| 5 | + {% comment %} Link for previous page {% endcomment %} |
| 6 | + {% if paginator.previous_page %} |
| 7 | + {% if paginator.previous_page == 1 %} |
| 8 | + <li><a href="{{ first_page_path }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li> |
| 9 | + {% else %} |
| 10 | + <li><a href="{{ site.paginate_path | replace: ':num', paginator.previous_page | replace: '//', '/' | relative_url }}">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</a></li> |
| 11 | + {% endif %} |
| 12 | + {% else %} |
| 13 | + <li><a href="#" class="disabled"><span aria-hidden="true">{{ site.data.ui-text[site.locale].pagination_previous | default: "Previous" }}</span></a></li> |
| 14 | + {% endif %} |
| 15 | + |
| 16 | + {% comment %} First page {% endcomment %} |
| 17 | + {% if paginator.page == 1 %} |
| 18 | + <li><a href="#" class="disabled current">1</a></li> |
| 19 | + {% else %} |
| 20 | + <li><a href="{{ first_page_path }}">1</a></li> |
| 21 | + {% endif %} |
| 22 | + |
| 23 | + {% assign page_start = 2 %} |
| 24 | + {% if paginator.page > 4 %} |
| 25 | + {% assign page_start = paginator.page | minus: 2 %} |
| 26 | + {% comment %} Ellipsis for truncated links {% endcomment %} |
| 27 | + <li><a href="#" class="disabled">…</a></li> |
| 28 | + {% endif %} |
| 29 | + |
| 30 | + {% assign page_end = paginator.total_pages | minus: 1 %} |
| 31 | + {% assign pages_to_end = paginator.total_pages | minus: paginator.page %} |
| 32 | + {% if pages_to_end > 4 %} |
| 33 | + {% assign page_end = paginator.page | plus: 2 %} |
| 34 | + {% endif %} |
| 35 | + |
| 36 | + {% for index in (page_start..page_end) %} |
| 37 | + {% if index == paginator.page %} |
| 38 | + <li><a href="{{ site.paginate_path | replace: ':num', index | replace: '//', '/' | relative_url }}" class="disabled current">{{ index }}</a></li> |
| 39 | + {% else %} |
| 40 | + {% comment %} Distance from current page and this link {% endcomment %} |
| 41 | + {% assign dist = paginator.page | minus: index %} |
| 42 | + {% if dist < 0 %} |
| 43 | + {% comment %} Distance must be a positive value {% endcomment %} |
| 44 | + {% assign dist = 0 | minus: dist %} |
| 45 | + {% endif %} |
| 46 | + <li><a href="{{ site.paginate_path | replace: ':num', index | relative_url }}">{{ index }}</a></li> |
| 47 | + {% endif %} |
| 48 | + {% endfor %} |
| 49 | + |
| 50 | + {% comment %} Ellipsis for truncated links {% endcomment %} |
| 51 | + {% if pages_to_end > 3 %} |
| 52 | + <li><a href="#" class="disabled">…</a></li> |
| 53 | + {% endif %} |
| 54 | + |
| 55 | + {% if paginator.page == paginator.total_pages %} |
| 56 | + <li><a href="#" class="disabled current">{{ paginator.page }}</a></li> |
| 57 | + {% else %} |
| 58 | + <li><a href="{{ site.paginate_path | replace: ':num', paginator.total_pages | replace: '//', '/' | relative_url }}">{{ paginator.total_pages }}</a></li> |
| 59 | + {% endif %} |
| 60 | + |
| 61 | + {% comment %} Link next page {% endcomment %} |
| 62 | + {% if paginator.next_page %} |
| 63 | + <li><a href="{{ site.paginate_path | replace: ':num', paginator.next_page | replace: '//', '/' | relative_url }}">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</a></li> |
| 64 | + {% else %} |
| 65 | + <li><a href="#" class="disabled"><span aria-hidden="true">{{ site.data.ui-text[site.locale].pagination_next | default: "Next" }}</span></a></li> |
| 66 | + {% endif %} |
| 67 | + </ul> |
| 68 | +</nav> |
| 69 | +{% endif %} |
0 commit comments