hugoWebsite/layouts/partials/pagination.html

56 lines
2.7 KiB
HTML
Raw Permalink Normal View History

2022-10-29 00:20:35 +02:00
{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }}
{{ $.Scratch.Set "dot_rendered" false }}
<nav class="flex items-center justify-center px-4 sm:px-0">
<div class="flex flex-1 w-0">
<div class="mx-auto border-t-2 border-primary-300">
2022-10-29 00:20:35 +02:00
<!-- Don't show on 1st and 2nd page -->
{{ if and (ne $pag.PageNumber 1) (ne $pag.PageNumber 2) }}
<a href="{{ $pag.First.URL }}" rel="first"
class="inline-flex items-center px-4 pt-4 text-lg font-black text-primary-600 dark:text-primary-400">«
2022-10-29 00:20:35 +02:00
First</a>
{{ end }}
{{ if $pag.HasPrev }}
<a href="{{ $pag.Prev.URL }}" rel="prev"
class="inline-flex items-center px-4 pt-4 text-lg font-black text-primary-600 dark:text-primary-400">
2022-10-29 00:20:35 +02:00
Prev</a>
{{ end }}
{{ range $pag.Pagers }}
{{ if eq . $pag }}
<!-- Current Page -->
<a class="font-black page-item active"><a href="{{ .URL }}"
class="inline-flex items-center px-4 pt-4 text-lg font-medium text-primary-600 dark:text-primary-400">{{ .PageNumber }}</a>
2022-10-29 00:20:35 +02:00
</a>
{{ else if and (ge .PageNumber (sub $pag.PageNumber 2)) (le .PageNumber (add $pag.PageNumber 2)) }}
{{ $.Scratch.Set "dot_rendered" false }}
<!-- Render prev 2 page and next 2 pages -->
<a class="page-item"><a href="{{ .URL }}"
class="inline-flex items-center px-4 pt-4 text-lg font-medium text-primary-600 dark:text-primary-400">{{ .PageNumber }}</a>
2022-10-29 00:20:35 +02:00
</a>
{{ else if eq ($.Scratch.Get "dot_rendered") false }}
<!-- render skip pages -->
{{ $.Scratch.Set "dot_rendered" true }}
<a class="page-item disabled"><a
class="inline-flex items-center px-4 pt-4 text-lg font-medium text-primary-600 dark:text-primary-400">...</a>
2022-10-29 00:20:35 +02:00
</a>
{{ end }}
{{ end }}
{{ if $pag.HasNext }}
<a class="page-item"><a href="{{ $pag.Next.URL }}" rel="next"
class="inline-flex items-center px-4 pt-4 text-lg font-black text-primary-600 dark:text-primary-400">Next
2022-10-29 00:20:35 +02:00
</a></a>
{{ end }}
<!-- Don't show on last and 2nd last page -->
{{ if and (ne $pag.PageNumber $pag.TotalPages) ((ne $pag.PageNumber (sub $pag.TotalPages 1))) }}
<a class="page-item"><a href="{{ $pag.Last.URL }}" rel="last"
class="inline-flex items-center px-4 pt-4 text-lg font-black text-primary-600 dark:text-primary-400">Last
2022-10-29 00:20:35 +02:00
»</a></a>
{{ end }}
</div>
</nav>
{{ end }}