bunteshaus.de/themes/buha/layouts/partials/structure/paginator.html

102 lines
2.9 KiB
HTML
Raw Normal View History

2022-04-03 21:31:40 +02:00
{{ $paginator := .paginator}}
2022-04-04 03:35:13 +02:00
<div id="pagination_outer" style="display: flex; justify-content: flex-end;">
2022-04-03 21:31:40 +02:00
<div id="pagination">
2022-04-03 21:08:42 +02:00
<!-- 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 }}
2022-04-03 21:31:40 +02:00
<!-- First page. -->
{{ if ne $paginator.PageNumber 1 }}
<a class="pagination__link pagination__link--first" href="{{ $paginator.First.URL }}">
««
</a>
{{ end }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
<!-- Previous page. -->
{{ if $paginator.HasPrev }}
<a href="{{ $paginator.Prev.URL }}" class="pagination__link pagination__link--previous">
«
</a>
{{ end }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
<!-- Page numbers. -->
{{ range $paginator.Pagers }}
{{ $page_number_flag := false }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
<!-- Advanced page numbers. -->
{{ if gt $paginator.TotalPages $max_links }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
<!-- Lower limit pages. -->
<!-- If the user is on a page which is in the lower limit. -->
{{ if le $paginator.PageNumber $lower_limit }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
<!-- If the current loop page is less than max_links. -->
{{ if le .PageNumber $max_links }}
{{ $page_number_flag = true }}
{{ end }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
<!-- Upper limit pages. -->
<!-- If the user is on a page which is in the upper limit. -->
{{ else if ge $paginator.PageNumber $upper_limit }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
<!-- If the current loop page is greater than total pages minus $max_links -->
{{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }}
{{ $page_number_flag = true }}
{{ end }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
<!-- Middle pages. -->
{{ else }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
{{ if and ( ge .PageNumber (sub $paginator.PageNumber $adjacent_links) ) ( le .PageNumber (add $paginator.PageNumber $adjacent_links) ) }}
{{ $page_number_flag = true }}
{{ end }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
{{ end }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
<!-- Simple page numbers. -->
{{ else }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
{{ $page_number_flag = true }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
{{ end }}
2022-04-03 21:08:42 +02:00
2022-04-03 21:31:40 +02:00
<!-- Output page numbers. -->
{{ if eq $page_number_flag true }}
<a href="{{ .URL }}" class="pagination__link">
{{ if eq $paginator.PageNumber .PageNumber }}<b>{{ end }}
{{ .PageNumber }}
{{ if eq $paginator.PageNumber .PageNumber }}</b>{{ end }}
</a>
{{ end }}
{{ end }}
2022-04-03 21:08:42 +02:00
<!-- Next page. -->
{{ if $paginator.HasNext }}
<a href="{{ $paginator.Next.URL }}" class="pagination__link pagination__link--next">
»
</a>
{{ end }}
<!-- Last page. -->
{{ if ne $paginator.PageNumber $paginator.TotalPages }}
<a class="pagination__link pagination__link--last" href="{{ $paginator.Last.URL }}">
»»
</a>
{{ end }}
{{ end }}
2022-04-04 03:35:13 +02:00
</div>
2022-04-03 21:08:42 +02:00
</div>