4 //––––––––––––––––––––––––––––––––––––––––––––––––––
5 // https://glennmccomb.com/articles/how-to-build-custom-hugo-pagination/
7 {{ $paginator := .Paginator }}
9 <!-- Number of links either side of the current page. -->
10 {{ $adjacent_links :=
2 }}
12 <!-- $max_links = ($adjacent_links * 2) + 1 -->
13 {{ $max_links := (add (mul $adjacent_links
2)
1) }}
15 <!-- $lower_limit = $adjacent_links + 1 -->
16 {{ $lower_limit := (add $adjacent_links
1) }}
18 <!-- $upper_limit = $paginator.TotalPages - $adjacent_links -->
19 {{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }}
21 <!-- If there's more than one page. -->
22 {{ if gt $paginator.TotalPages
1 }}
24 <ul class=
"pagination align-center">
27 {{ if ne $paginator.PageNumber
1 }}
29 <a class=
"page" href=
"{{ $paginator.First.URL }}">
30 <span class=
"button small">FIRST
</span>
35 <!-- Previous page. -->
36 {{ if $paginator.HasPrev }}
38 <a class=
"page" href=
"{{ $paginator.Prev.URL }}">
39 <span class=
"button small">PREV
</span>
44 <!-- Page numbers. -->
45 {{ range $paginator.Pagers }}
47 {{ $.Scratch.Set
"page_number_flag" false }}
50 <!-- Advanced page numbers. -->
51 {{ if gt $paginator.TotalPages $max_links }}
54 <!-- Lower limit pages. -->
55 <!-- If the user is on a page which is in the lower limit. -->
56 {{ if le $paginator.PageNumber $lower_limit }}
58 <!-- If the current loop page is less than max_links. -->
59 {{ if le .PageNumber $max_links }}
60 {{ $.Scratch.Set
"page_number_flag" true }}
64 <!-- Upper limit pages. -->
65 <!-- If the user is on a page which is in the upper limit. -->
66 {{ else if ge $paginator.PageNumber $upper_limit }}
68 <!-- If the current loop page is greater than total pages minus $max_links -->
69 {{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }}
70 {{ $.Scratch.Set
"page_number_flag" true }}
74 <!-- Middle pages. -->
77 {{ if and ( ge .PageNumber (sub $paginator.PageNumber $adjacent_links) ) ( le .PageNumber (add $paginator.PageNumber $adjacent_links) ) }}
78 {{ $.Scratch.Set
"page_number_flag" true }}
84 <!-- Simple page numbers. -->
87 {{ $.Scratch.Set
"page_number_flag" true }}
91 <!-- Output page numbers. -->
92 {{ if eq ($.Scratch.Get
"page_number_flag") true }}
94 <a href=
"{{ .URL }}" class=
"page {{ if eq . $paginator }} active{{ end }}">
103 {{ if $paginator.HasNext }}
105 <a href=
"{{ $paginator.Next.URL }}" class=
"page">
106 <span class=
"button small">NEXT
</span>
112 {{ if ne $paginator.PageNumber $paginator.TotalPages }}
114 <a class=
"page" href=
"{{ $paginator.Last.URL }}">
115 <span class=
"button small">LAST
</span>
120 </ul><!-- .pagination -->