paginator.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. {{ $pag := $.Paginator }}
  2. {{ if gt $pag.TotalPages 1 }}
  3. <nav class="blog-pagination">
  4. <ul class="pagination justify-content-center">
  5. {{ with $pag.First }}
  6. <li class="page-item">
  7. <a class="page-link" href="{{ .URL }}" aria-label="First"><span aria-hidden="true">&laquo;&laquo;</span></a>
  8. </li>
  9. {{ end }}
  10. <li class="page-item {{ if not $pag.HasPrev }}disabled{{ end }}">
  11. <a class="page-link" href="{{ if $pag.HasPrev }}{{ $pag.Prev.URL }}{{ else }}#{{ end }}" aria-label="Previous" {{ if not $pag.HasPrev }}tabindex="-1" aria-disabled="true"{{ end }}><span aria-hidden="true">&laquo;</span></a>
  12. </li>
  13. {{ $.Scratch.Set "__paginator.ellipsed" false }}
  14. {{ range $pag.Pagers }}
  15. {{ $right := sub .TotalPages .PageNumber }}
  16. {{ $showNumber := or (le .PageNumber 3) (eq $right 0) }}
  17. {{ $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) }}
  18. {{ if $showNumber }}
  19. {{ $.Scratch.Set "__paginator.ellipsed" false }}
  20. {{ $.Scratch.Set "__paginator.shouldEllipse" false }}
  21. {{ else }}
  22. {{ $.Scratch.Set "__paginator.shouldEllipse" (not ($.Scratch.Get "__paginator.ellipsed") ) }}
  23. {{ $.Scratch.Set "__paginator.ellipsed" true }}
  24. {{ end }}
  25. {{ if $showNumber }}
  26. <li class="page-item {{ if eq . $pag }}active{{ end }}">
  27. <a class="page-link" href="{{ .URL }}">{{ .PageNumber }}</a>
  28. </li>
  29. {{ else if ($.Scratch.Get "__paginator.shouldEllipse") }}
  30. <li class="page-item disabled">
  31. <span class="page-link" aria-hidden="true">&hellip;</span>
  32. </li>
  33. {{ end }}
  34. {{ end }}
  35. <li class="page-item {{ if not $pag.HasNext }}disabled{{ end }}">
  36. <a class="page-link" href="{{ if $pag.HasNext }}{{ $pag.Next.URL }}{{ else }}#{{ end }}" aria-label="Next" {{ if not $pag.HasPrev }}tabindex="-1" aria-disabled="true"{{ end }}><span aria-hidden="true">&raquo;</span></a>
  37. </li>
  38. {{ with $pag.Last }}
  39. <li class="page-item">
  40. <a class="page-link" href="{{ .URL }}" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
  41. </li>
  42. {{ end }}
  43. </ul>
  44. </nav>
  45. {{ end }}