[SOLVED]Create pagination pages in meta canonical

I use hugo 0.27.1 in arch

how can i use pagination pages like <link rel = "canonical" href = "https://example.com/page/2/" />

if I use {{ .Permalink }} just show <link rel = "canonical" href = "https://example.com/" /> on the next page

sorry i use google translate.

thanks.

[SOLVED]

{{ $pag := .Paginate .Data.Pages }}
{{ if $pag.HasPrev }}
     <link rel="canonical" href="{{ .Paginator.URL | absURL}}" />
{{ else }}
     <link rel="canonical" href="{{ .Permalink }}" />
{{end}}
2 Likes

And, let’s say you are using this on a blog section and perhaps have a featured post at the top of the first page (i.e. not a paginated page). You could then add ‘not’:

{{ $pag := .Paginate .Data.Pages }}
{{ if not $pag.HasPrev }}
   <h1>My very special featured post</h1>
{{ else }}
   // Nothing, or something else here for our paginated pages
{{ end }}
1 Like