2020-11-02 08:53:37 +00:00
{{ $pag := .Paginator }}
{{- /* The minimum pages starting from the first page */ -}}
{{ $minimumPage := .minimumPage | default 1 }}
{{- /* The number of pages to be shown with the active page. */ -}}
{{ $activeNumberOfPages := .activeNumberOfPages | default 2 }}
{{- /* Since the active page is also included when adding the in-between pages of the active page, we need to increment it to mitigate against it. */ -}}
{{ $midpointPages := add $activeNumberOfPages 1 }}
{{ if gt $pag.TotalPages 1 -}}
< ul class = "pagination" >
{{- $ellipsed := false -}}
{{- $shouldEllipse := false -}}
{{- range $pag.Pagers -}}
2020-11-05 05:54:38 +00:00
{{ $minimumActivePage := sub $pag.PageNumber $activeNumberOfPages }}
{{ $maximumActivePage := add $pag.PageNumber $activeNumberOfPages }}
2020-11-02 08:53:37 +00:00
2020-11-05 05:54:38 +00:00
{{- /* Make all of the given number of pages starting from both ends to be visible */ -}}
{{- $showNumber := or (le .PageNumber $minimumPage) (lt (sub .TotalPages .PageNumber) $minimumPage) -}}
2020-11-02 08:53:37 +00:00
2020-11-05 05:54:38 +00:00
{{- /* Make all of the given number of pages between the active page number visible */ -}}
{{- $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber $midpointPages)) (lt .PageNumber (add $pag.PageNumber $midpointPages))) -}}
2020-11-02 08:53:37 +00:00
2020-11-05 05:54:38 +00:00
{{- /*
Make all of the page number that is just before/after the minimum page threshold to be visible.
This is applied to those situations where there's only one number remaining before the end
*/ -}}
{{ if eq .PageNumber (sub $minimumActivePage 1) }}
{{ $showNumber = or $showNumber (eq (sub $minimumActivePage $minimumPage) (add $pag.First.PageNumber 1)) }}
{{ else if eq .PageNumber (add $maximumActivePage 1) }}
{{ $showNumber = or $showNumber (eq (add $maximumActivePage 1) (sub $pag.Last.PageNumber $minimumPage)) }}
{{ end }}
2020-11-02 08:53:37 +00:00
2020-11-05 05:54:38 +00:00
{{- if $showNumber -}}
{{- $ellipsed = false -}}
{{- $shouldEllipse = false -}}
{{- else -}}
{{- $shouldEllipse = not $ellipsed -}}
{{- $ellipsed = true -}}
{{- end -}}
{{- if $showNumber }}
< li >
2020-11-02 08:53:37 +00:00
< a class = "page-link{{ if eq . $pag }}--active{{ end }}" href = "{{ .URL }}"
2021-01-20 23:43:38 +00:00
{{- if eq (sub $pag.PageNumber .PageNumber) 1 }}
rel="prev"
aria-label="Previous"
{{- else if (eq (sub $pag.PageNumber .PageNumber) -1) }}
rel="next"
aria-label="Next"
{{- else if (eq $pag.PageNumber .PageNumber) }}
aria-label="Current"
aria-current="page"
{{- end -}}
2020-11-02 08:53:37 +00:00
>{{ .PageNumber }}< / a >
2020-11-05 05:54:38 +00:00
< / li >
{{- else if $shouldEllipse }}
< li class = "page-item disabled" >
< span aria-hidden = "true" > … < / span >
< / li >
{{- end -}}
2020-11-02 08:53:37 +00:00
{{- end }}
< / ul >
{{ end }}