This repository has been archived by the owner on Aug 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Truncate pagination links with [...] to avoid long lists
- Loading branch information
Showing
2 changed files
with
67 additions
and
34 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{% if paginator.total_pages > 1 %} | ||
<div class="pagination"> | ||
<ul class="inline-list"> | ||
{% comment %} Link for previous page {% endcomment %} | ||
{% if paginator.previous_page %} | ||
{% if paginator.previous_page == 1 %} | ||
<li><a href="{{ site.url }}" class="btn">Previous</a></li> | ||
{% else %} | ||
<li><a href="{{ site.url }}/page{{ paginator.previous_page }}/" class="btn">Previous</a></li> | ||
{% endif %} | ||
{% endif %} | ||
|
||
{% comment %} First page {% endcomment %} | ||
{% if paginator.page == 1 %} | ||
<li><strong class="current-page">1</strong></li> | ||
{% else %} | ||
<li><a href="{{ site.url }}">1</a></li> | ||
{% endif %} | ||
|
||
{% assign page_start = 2 %} | ||
{% if paginator.page > 4 %} | ||
{% assign page_start = paginator.page | minus: 2 %} | ||
{% comment %} Ellipsis for truncated links {% endcomment %} | ||
<li>…</li> | ||
{% endif %} | ||
|
||
{% assign page_end = paginator.total_pages | minus: 1 %} | ||
{% assign pages_to_end = paginator.total_pages | minus: paginator.page %} | ||
{% if pages_to_end > 4 %} | ||
{% assign page_end = paginator.page | plus: 2 %} | ||
{% endif %} | ||
|
||
{% for index in (page_start..page_end) %} | ||
{% if index == paginator.page %} | ||
<li><strong class="current-page">{{index}}</strong></li> | ||
{% else %} | ||
{% comment %} Distance from current page and this link {% endcomment %} | ||
{% assign dist = paginator.page | minus: index %} | ||
{% if dist < 0 %} | ||
{% comment %} Distance must be a positive value {% endcomment %} | ||
{% assign dist = 0 | minus: dist %} | ||
{% endif %} | ||
<li><a href="{{ site.url }}/page{{ index }}/">{{index}}</a></li> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% comment %} Ellipsis for truncated links {% endcomment %} | ||
{% if pages_to_end > 3 %} | ||
<li>…</li> | ||
{% endif %} | ||
|
||
{% if paginator.page == paginator.total_pages %} | ||
<li><strong class="current-page">{{ paginator.page }}</strong></li> | ||
{% else %} | ||
<li><a href="{{ site.url }}/page{{ paginator.total_pages }}/">{{ paginator.total_pages }}</a></li> | ||
{% endif %} | ||
|
||
{% comment %} | ||
Link next page | ||
{% endcomment %} | ||
{% if paginator.next_page %} | ||
<li><a href="{{ site.url }}/page{{ paginator.next_page }}/" class="btn">Next</a></li> | ||
{% endif %} | ||
</ul> | ||
</div> | ||
{% endif %} |
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