Sorting Front Matter Keys with Hugo New

v0.18.1 BuildDate: 2016-12-29T12:12:41-05:00

The command hugo new outputs front matter in the resulting file in alphabetical order.

Archetype:
---
foo: ""
bar: ""
---

Ouputs:

---
bar: ""
foo: ""
---

My expectation would be that the output would respect the order I created in the archetype.

While alphabetical enforces consistency, I think it’s important to control the order to suit the content, particularly for non-technical editors, and even more particularly for more complex content where there’s meaning to the hierarchy (for instance, more important keys, like “title” at the top).

I don’t see any indication or flag for this in the docs. Surprised not to find anything in the forums on this either.

Is there a way to get what I want, or is this a feature request?

This has been discussed before, I would use search on GitHub.

This is implemented using Go maps. They’re famous for guaranteeing that you can rely on any ordering.

That makes it unlikely that any sort of ordering will be supported in Hugo.

@budparr I’m one of the worst offenders of bringing up repeat issues :smile:

Hopefully these help. FWIW, I’ve made note of this as a callout/admonishment in the docs concept I’ve been working on. Cheers!

1 Like

Apologies for the duplicate. Doesn’t seem to me the issues here on the forums addressed it precisely, but I hadn’t looked at the repo. I see the most relevant issue as https://github.com/spf13/hugo/issues/452 and at the moment it is “Please Contribute” so not on the radar.