Fixing Hugo pagination in 0.58

Internet

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

Me!

Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

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

You can leave me a comment by contacting me, and I might publish your thoughts. Please read the FAQs first though.

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!