diff options
Diffstat (limited to 'layouts/partials/pagination.html')
-rw-r--r-- | layouts/partials/pagination.html | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/layouts/partials/pagination.html b/layouts/partials/pagination.html new file mode 100644 index 0000000..0822d0a --- /dev/null +++ b/layouts/partials/pagination.html @@ -0,0 +1,125 @@ +<!--Paginator nav--> +<div class="flex mt-10"> + + {{ $paginator := .Paginator }} + + <!-- Number of links either side of the current page. --> + {{ $adjacent_links := 2 }} + + <!-- $max_links = ($adjacent_links * 2) + 1 --> + {{ $max_links := (add (mul $adjacent_links 2) 1) }} + + <!-- $lower_limit = $adjacent_links + 1 --> + {{ $lower_limit := (add $adjacent_links 1) }} + + <!-- $upper_limit = $paginator.TotalPages - $adjacent_links --> + {{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }} + + <!-- If there's more than one page. --> + {{ if gt $paginator.TotalPages 1 }} + + <ul class="inline-block"> + + <!-- First page. --> + {{ if ne $paginator.PageNumber 1 }} + <li class="inline-block"> + <a href="{{ $paginator.First.URL }}" class="link" title="First page"> + First + </a> + </li> + {{ end }} + + <!-- Previous page. --> + {{ if $paginator.HasPrev }} + <li class="inline-block"> + <a href="{{ $paginator.Prev.URL }}" class="link mx-1" title="Previous page"> + Prev + </a> + </li> + {{ end }} + + <!-- Page numbers. --> + {{ range $paginator.Pagers }} + + {{ $.Scratch.Set "page_number_flag" false }} + + + <!-- Advanced page numbers. --> + {{ if gt $paginator.TotalPages $max_links }} + + + <!-- Lower limit pages. --> + <!-- If the user is on a page which is in the lower limit. --> + {{ if le $paginator.PageNumber $lower_limit }} + + <!-- If the current loop page is less than max_links. --> + {{ if le .PageNumber $max_links }} + {{ $.Scratch.Set "page_number_flag" true }} + {{ end }} + + + <!-- Upper limit pages. --> + <!-- If the user is on a page which is in the upper limit. --> + {{ else if ge $paginator.PageNumber $upper_limit }} + + <!-- If the current loop page is greater than total pages minus $max_links --> + {{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }} + {{ $.Scratch.Set "page_number_flag" true }} + {{ end }} + + + <!-- Middle pages. --> + {{ else }} + + {{ if and ( ge .PageNumber (sub $paginator.PageNumber $adjacent_links) ) ( le .PageNumber (add $paginator.PageNumber $adjacent_links) ) }} + {{ $.Scratch.Set "page_number_flag" true }} + {{ end }} + + {{ end }} + + + <!-- Simple page numbers. --> + {{ else }} + + {{ $.Scratch.Set "page_number_flag" true }} + + {{ end }} + + <!-- Output page numbers. --> + {{ if eq ($.Scratch.Get "page_number_flag") true }} + <li class="inline-block"> + {{ if eq . $paginator }} + <span class="font-semibold mx-1"> + {{ .PageNumber }} + </span> + {{else}} + <a href="{{ .URL }}" class="link mx-1"> + {{ .PageNumber }} + </a> + {{ end }} + </li> + {{ end }} + + {{ end }} + + <!-- Next page. --> + {{ if $paginator.HasNext }} + <li class="inline-block"> + <a href="{{ $paginator.Next.URL }}" class="link mx-1" title="Next page"> + Next + </a> + </li> + {{ end }} + + <!-- Last page. --> + {{ if ne $paginator.PageNumber $paginator.TotalPages }} + <li class="inline-block"> + <a href="{{ $paginator.Last.URL }}" title="Last page" class="link"> + Last + </a> + </li> + {{ end }} + + </ul> + {{ end }} + </div>
\ No newline at end of file |