Skip to content

Commit

Permalink
Pagination - do not render href if no next item
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
markmandel authored and bep committed Jun 26, 2019
1 parent 59c4bc5 commit 88c8a15
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tpl/tplimpl/embedded/templates/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -29,12 +29,12 @@
{{ 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">
<a href="{{ .URL }}" class="page-link" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
</li>
{{ end }}
</ul>
{{ end }}
{{ end }}

0 comments on commit 88c8a15

Please sign in to comment.