Before publishing the changes I make, I run Xenu over Hugo’s Server URL to check if I didn’t leave behind anything broken.
Today I noticed A LOT of pages had the same title. Some of them it’s a little out of my control because they’re untranslatable names but others, like pages of listing results, could be worked to add Paginator’s data and get rid of this SEO issue.
Then I’ve coded the following routine in my partials/headers.html
, prepended in all other templates:
{{ $.Scratch.Set "title" "" }}
{{ if ( and (ne .Title "") (not .IsHome) (ne .Kind "post") ) }}
{{ $.Scratch.Set "title" (.Title | plainify) }}
{{ end }}
<!-- Appending Paginator Data, if needed -->
{{ if (ne .Kind "page") }}
{{ if (or (.Paginator.HasPrev) (.Paginator.HasNext) ) }}
{{ $prefix := (i18n "paginator-page-prefix" | default "__MISSING__") }}
{{ $of := (i18n "paginator-page-connector" | default "__MISSING__") }}
{{ $c := (.Paginator.PageNumber) }}
{{ $t := (.Paginator.TotalPages) }}
{{ $.Scratch.Set "title" (printf "%s | %s %d %s %d" ($.Scratch.Get "title") ($prefix) ($c) ($of) ($t) ) }}
{{ end }}
{{ end }}
<!-- Appending Site Name -->
{{ $i18n := i18n "title-site-name-full" | default "__MISSING__" }}
{{ $.Scratch.Set "title" (printf "%s | %s" ($.Scratch.Get "title") ($i18n) ) }}
<title>{{ $.Scratch.Get "title" }}</title>
And after re-syncing, the titles of my listing results pages had Page Title | Page X of Y | Site Name
.
It would be perfect, but that broke the Paginator itself.
In my _default;list.html
I have nothing that could be causing this issue, or at least I think:
{{ $items := (.Paginator 6).Pages }}
{{ range $offset, $current := $items }}
// Lots of logic and markups to build different types of paginations
{{ end }}
{{ if or .Paginator.HasPrev .Paginator.HasNext }}
// Pagination markup
{{ end }}
Without the modification I made to build a richer and more SEO-friendly <title>
all Paginations work perfectly showing a maximum of 6 items per page, but adding that code I have 10.
I didn’t set 10
anywhere of my code or in my config.toml
prior to this issue, but I assume that there’s a hidden, forced default value because when I manually set paginate = 6
everything worked as intended.
Still, I would like to know if I can do this in template-time because otherwise, it’s of no use putting the 6
over there.