Hugo: v0.120.0
Hello everyone! I am making a meta tag for page navigation (first, last, prev, next). When I add the construction:
{{ with ($.Paginator) }}
{{ $canonical = ((.URL) | absURL) }}
<link rel="first" href="{{ ((.First.URL) | absURL) }}"/>
<link rel="last" href="{{ ((.Last.URL) | absURL) }}"/>
{{ if (.HasPrev) }}
<link rel="prev" href="{{ ((.Prev.URL) | absURL) }}"/>
{{ end }}
{{ if (.HasNext) }}
<link rel="next" href="{{ ((.Next.URL) | absURL) }}"/>
{{ end }}
{{ end }}
…the list of articles from the archive disappears. I remove the construction and a list of articles appears. I can’t understand what’s wrong.
Below is the code for generating the canonical url and the code from the archive template.
head.html:
{{ $canonical := (.Permalink) }}
{{ with ($.Paginator) }}
{{ $canonical = ((.URL) | absURL) }}
<link rel="first" href="{{ ((.First.URL) | absURL) }}"/>
<link rel="last" href="{{ ((.Last.URL) | absURL) }}"/>
{{ if (.HasPrev) }}
<link rel="prev" href="{{ ((.Prev.URL) | absURL) }}"/>
{{ end }}
{{ if (.HasNext) }}
<link rel="next" href="{{ ((.Next.URL) | absURL) }}"/>
{{ end }}
{{ end }}
<link rel="canonical" href="{{ ($canonical) }}"/>
archive.html:
{{ define "main" }}
{{ $posts := (where (site.RegularPages) "Type" "in" (site.Params.sections)) }}
{{ (partial "breadcrumb" .) }}
{{ if ($posts) }}
{{ range (.Paginate ($posts.GroupByDate "2006") 50).PageGroups }}
<div class="row mb-3">
<div class="col">
<article>
<h2>{{ (.Key) }}</h2>
<div class="node-body">
<ul class="list-unstyled">
{{ range (.Pages) }}
<li class="d-flex">
<div class="me-3"><code>{{ (.Date.UTC.Format "01/02") }}</code></div>
<div class="flex-grow-1"><a href="{{ (.RelPermalink) }}">{{ (.Title) }}</a></div>
</li>
{{ end }}
</ul>
</div>
</article>
</div>
</div>
{{ end }}
{{ end }}
{{ (partial "pagination" .) }}
{{ end }}