Fixing Hugo pagination in 0.58


The latest Hugo static site generator version broke pagination for all my sites, including this one. This is how I previously filtered content so only posts would appear in pagination, as per the documentation:

{{ $paginator := .Paginate (where .Pages "Type" "post") }}
{{ range $paginator.Pages }}

This now returnes a single page with the word Posts shown, and nothing else. I changed to the generic pagination method below and it worked, so the issue was with the above lookup.

{{ range .Pagination.Pages }}

I saw this thread on the Hugo forums, which had example code by funkydan2 replacing .Pages with site.RegularPages. This worked.

{{ $pages := where site.RegularPages "Type" "post" }}
{{ $paginator := .Paginate $pages }}{{ range $paginator.Pages }}

I broke the lookup out into a separate line to make it nicer, but you can just do a replace with the original documented code and it works.

Niggling changes like this aside, Hugo is still the best static-site generator I’ve ever used. I do miss the Liquid template system of Jekyll, but Hugo generates more than six thousand posts in seconds, as opposed to more than fifteen minutes. I wonder how much wasted power I’ve saved on remote servers since making the switch.

Author bio and support


Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.