shithub: hugo

Download patch

ref: 4b560cc1197ad07252fbb9a080c06f2f361c2b0e
parent: e3e627e6b706a67abb3d7752b27326c07326b53d
author: Joe Mooring <joe.mooring@veriphor.com>
date: Tue Apr 21 14:49:30 EDT 2020

Beautify HTML generated by pagination template

Fixes #7199.

--- a/tpl/tplimpl/embedded/templates/pagination.html
+++ b/tpl/tplimpl/embedded/templates/pagination.html
@@ -1,40 +1,44 @@
 {{ $pag := $.Paginator }}
-{{ if gt $pag.TotalPages 1 }}
+{{ if gt $pag.TotalPages 1 -}}
 <ul class="pagination">
-    {{ with $pag.First }}
-    <li class="page-item">
-        <a href="{{ .URL }}" 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 }}">
+  {{ with $pag.First -}}
+  <li class="page-item">
+    <a href="{{ .URL }}" 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 }}"{{ 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 }}">{{ .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 }}">
+  </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 }}">{{ .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 }}"{{ 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 }}" class="page-link" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
-    </li>
-    {{ end }}
+  </li>
+  {{- with $pag.Last }}
+  <li class="page-item">
+    <a href="{{ .URL }}" class="page-link" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
+  </li>
+  {{- end }}
 </ul>
 {{ end }}