fizz.today

Hugo’s {{ range .Pages }} sorts oldest-first

I published 40 TILs before I noticed my blog index was listing them in the wrong order. Newest posts were buried at the bottom. Same-day posts were in random order. I assumed Hugo would default to reverse-chronological like every blog platform I’ve used since Movable Type in 2001.

It doesn’t. {{ range .Pages }} sorts by date ascending — oldest first. The bearblog theme I’m using doesn’t override this. Neither did I, because I assumed a blog theme would ship with blog defaults.

The fix is {{ range .Pages.ByDate.Reverse }} in layouts/_default/list.html. One word, 40 posts of wrong ordering.

The same-day scrambling was a second bug hiding behind the first. Posts with bare dates like date = "2026-02-14" default to midnight UTC. When six posts share a date and all resolve to the same timestamp, Hugo picks whatever tiebreaker it feels like — filename, file modification time, phase of the moon. I’d been manually reordering posts for weeks without understanding why they kept drifting.

The fix for that is timestamps on every post: date = "2026-02-14T09:00:00-06:00". Space same-day posts an hour apart and the sort is deterministic.

Two bugs, two one-line fixes, 40 posts of accumulated wrongness. I was so eager to start publishing that I never checked whether the list was in the right order.

#hugo #blogging