gcg-website/layouts/partials/pagination.html

67 lines
2.2 KiB
HTML
Raw Permalink Normal View History

{{ $paginator := .Paginator }}
{{ $adjacent_links := 2 }}
{{ $max_links := (add (mul $adjacent_links 2) 1) }}
{{ $lower_limit := (add $adjacent_links 1) }}
{{ $upper_limit := (sub $paginator.TotalPages $adjacent_links) }}
{{ if gt $paginator.TotalPages 1 }}
<nav>
<ul class="pagination">
{{ if ne $paginator.PageNumber 1 }}
<li class="page-item">
<a class="page-link" href="{{ $paginator.First.URL }}">
2024-01-20 20:09:43 +01:00
{{ partial "mdi" "step-backward-2" }}
</a>
</li>
{{ end }}
{{ if $paginator.HasPrev }}
<li class="page-item">
<a href="{{ $paginator.Prev.URL }}" class="page-link">
2024-01-20 20:09:43 +01:00
{{ partial "mdi" "step-backward" }}
</a>
</li>
{{ end }}
{{ range $paginator.Pagers }}
{{ $.Scratch.Set "page_number_flag" false }}
{{ if gt $paginator.TotalPages $max_links }}
{{ if le $paginator.PageNumber $lower_limit }}
{{ if le .PageNumber $max_links }}
{{ $.Scratch.Set "page_number_flag" true }}
{{ end }}
{{ else if ge $paginator.PageNumber $upper_limit }}
{{ if gt .PageNumber (sub $paginator.TotalPages $max_links) }}
{{ $.Scratch.Set "page_number_flag" true }}
{{ end }}
{{ 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 }}
{{ else }}
{{ $.Scratch.Set "page_number_flag" true }}
{{ end }}
{{ if eq ($.Scratch.Get "page_number_flag") true }}
<li class="page-item {{ if eq . $paginator }}active{{ end }}">
<a href="{{ .URL }}" class="page-link">
{{ .PageNumber }}
</a>
</li>
{{ end }}
{{ end }}
{{ if $paginator.HasNext }}
<li class="page-item">
<a href="{{ $paginator.Next.URL }}" class="page-link">
2024-01-20 20:09:43 +01:00
{{ partial "mdi" "step-forward" }}
</a>
</li>
{{ end }}
{{ if ne $paginator.PageNumber $paginator.TotalPages }}
<li class="page-item">
<a class="page-link" href="{{ $paginator.Last.URL }}">
2024-01-20 20:09:43 +01:00
{{ partial "mdi" "step-forward-2" }}
</a>
</li>
{{ end }}
</ul>
</nav>
{{ end }}