Fix links on the pagination

This commit is contained in:
Thomas Schwery 2020-02-08 22:24:43 +01:00
parent f635df8c7b
commit 7224339674
2 changed files with 51 additions and 1 deletions

View file

@ -18,7 +18,7 @@
</div>
<div class="content row justify-content-center">
<div class="col-4 mb-3 mt-3">
{{ template "_internal/pagination.html" . }}
{{ template "partials/pagination.html" . }}
</div>
</div>
</div>

View file

@ -0,0 +1,50 @@
{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }}
<ul class="pagination">
{{ with $pag.First }}
<li class="page-item">
<a href="{{ .URL }}index.html" class="page-link" aria-label="First">
<span aria-hidden="true">&laquo;&laquo;</span>
</a>
</li>
{{ end }}
<li class="page-item{{ if not $pag.HasPrev }} disabled{{ end }}">
<a {{ if $pag.HasPrev }}href="{{ $pag.Prev.URL }}index.html"{{ end }} class="page-link" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{{ $ellipsed := false }}
{{ $shouldEllipse := false }}
{{ range $pag.Pagers }}
{{ $right := sub .TotalPages .PageNumber }}
{{ $showNumber := or (le .PageNumber 3) (eq $right 0) }}
{{ $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) }}
{{ if $showNumber }}
{{ $ellipsed = false }}
{{ $shouldEllipse = false }}
{{ else }}
{{ $shouldEllipse = not $ellipsed }}
{{ $ellipsed = true }}
{{ end }}
{{ if $showNumber }}
<li class="page-item{{ if eq . $pag }} active{{ end }}">
<a class="page-link" href="{{ .URL }}index.html">{{ .PageNumber }}</a>
</li>
{{ else if $shouldEllipse }}
<li class="page-item disabled"><span aria-hidden="true">&nbsp;&hellip;&nbsp;</span></li>
{{ end }}
{{ end }}
<li class="page-item{{ if not $pag.HasNext }} disabled{{ end }}">
<a {{ if $pag.HasNext }}href="{{ $pag.Next.URL }}index.html"{{ end }} class="page-link" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{{ with $pag.Last }}
<li class="page-item">
<a href="{{ .URL }}index.html" class="page-link" aria-label="Last">
<span aria-hidden="true">&raquo;&raquo;</span>
</a>
</li>
{{ end }}
</ul>
{{ end }}