blogamore/layouts/partials/pagination.html

38 lines
1.8 KiB
HTML
Raw Permalink Normal View History

2022-11-13 20:52:45 +01:00
{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }}
{{ $.Scratch.Set "dot_rendered" false }}
<nav aria-label="page navigation">
<ul class="pagination">
<!-- Don't show on 1st and 2nd page -->
{{- if and (ne $pag.PageNumber 1) (ne $pag.PageNumber 2) -}}
2022-11-13 20:52:45 +01:00
<li class="page-item"><a href="{{ $pag.First.URL }}" rel="first" class="page-link">&laquo;</a></li>
{{- end -}}
2022-11-13 20:52:45 +01:00
{{- if $pag.HasPrev }}
2022-11-13 20:52:45 +01:00
<li class="page-item"><a href="{{ $pag.Prev.URL }}" rel="prev" class="page-link">&lsaquo;</a></li>
{{- end -}}
2022-11-13 20:52:45 +01:00
{{- range $pag.Pagers -}}
{{- if eq . $pag -}} <!-- Current Page -->
2022-11-13 20:52:45 +01:00
<li class="page-item active"><a href="{{ .URL }}" class="page-link">{{ .PageNumber }}</a></li>
{{- 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 -->
2022-11-13 20:52:45 +01:00
<li class="page-item"><a href="{{ .URL }}" class="page-link">{{ .PageNumber }}</a></li>
{{- else if eq ($.Scratch.Get "dot_rendered") false }} <!-- render skip pages -->
{{- $.Scratch.Set "dot_rendered" true }}
2022-11-13 20:52:45 +01:00
<li class="page-item disabled"><a class="page-link">...</a></li>
{{- end }}
{{- end -}}
2022-11-13 20:52:45 +01:00
{{- if $pag.HasNext }}
2022-11-13 20:52:45 +01:00
<li class="page-item"><a href="{{ $pag.Next.URL }}" rel="next" class="page-link">&rsaquo;</a></li>
{{- end -}}
2022-11-13 20:52:45 +01:00
<!-- Don't show on last and 2nd last page -->
{{- if and (ne $pag.PageNumber $pag.TotalPages) ((ne $pag.PageNumber (sub $pag.TotalPages 1))) }}
2022-11-13 20:52:45 +01:00
<li class="page-item"><a href="{{ $pag.Last.URL }}" rel="last" class="page-link">&raquo;</a></li>
{{- end }}
2022-11-13 20:52:45 +01:00
</ul>
</nav>
{{- end }}