Pagination - do not render href if no next item
authorMark Mandel <markmandel@google.com>
Wed, 26 Jun 2019 20:31:06 +0000 (13:31 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 26 Jun 2019 20:38:30 +0000 (22:38 +0200)
When using a html link checker with Hugo, this template consistently causes errors, as it renders `href=""` attributes when next/previous is disabled.

This change makes it so that the `href` attribute is not rendered at all if `HasNext` is false - which is better semantically, and makes link checking far easier.

tpl/tplimpl/embedded/templates/pagination.html

index 1c2d2d82f2f412e9a398897e3bdc2789744a355e..896e655fe5d6d739cfa2edd2e76276b0ed693ff7 100644 (file)
@@ -7,7 +7,7 @@
     </li>
     {{ end }}
     <li class="page-item{{ if not $pag.HasPrev }} disabled{{ end }}">
-    <a href="{{ if $pag.HasPrev }}{{ $pag.Prev.URL }}{{ end }}" class="page-link" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
+    <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 }}
@@ -29,7 +29,7 @@
     {{ end }}
     {{ end }}
     <li class="page-item{{ if not $pag.HasNext }} disabled{{ end }}">
-    <a href="{{ if $pag.HasNext }}{{ $pag.Next.URL }}{{ end }}" class="page-link" aria-label="Next"><span aria-hidden="true">&raquo;</span></a>
+    <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">
@@ -37,4 +37,4 @@
     </li>
     {{ end }}
 </ul>
-{{ end }}
\ No newline at end of file
+{{ end }}