If you have a post with only one category, and choose between adding it to your post’s YAML metadata in one of the following ways:

categories:
- Category Name
categories: Category Name

Those are not the same! According to Hugo, the first one is an array (of one item), and the second one is a string. So then if you later want to make a template where you range all posts’ categories, it’s going to break because you can’t range a string, and the error message is not going to tell you which specific page is broken but only its category and what kind of feed is breaking (a section feed, a term feed, etc.), so you are going to have to go through every single one of your old posts in the relevant category until you find which one is causing the issue.

I mean sure, in retrospect it makes sense that Hugo wouldn’t know to interpret categories: Category Name as a single-item array and not a string. Indeed I guess I always knew there was something not-quite-right about that format, because I didn’t have that many old posts I had to fix up today. I had enough to be annoying, though. Mostly I don’t mind not having/using a CMS to manage my site but at times like this… 🤨

In other news, my RSS feeds include individual posts’ categories now, in line with a suggestion from this blog post about RSS Feed Best Practices(external link). I actually have no idea which feed readers make use of this info (I don’t think mine does) but it seems potentially useful to some people so I added it. It does occur to me that it might also be useful to add section (e.g. Posts, Links, Book Reviews) if it means readers could filter sections they’re not interested in out of the full feed. I haven’t done that yet, though. I was traumatised enough by this damn array vs. string issue 🤣

EDIT: For SEO purposes, maybe I should actually add the error message you’ll see if you make the same mistake that I did. If you have categories listed in posts as strings, when you try to range them as arrays, your build will fail with errors that include range can't iterate over [CATEGORY NAME] like:

ERROR 2022/05/12 15:41:20 render of "term" failed: "/Users/jess/Documents/GitHub/jayeless.net/layouts/_default/rss.xml:75:13": execute of template failed: template: _default/rss.xml:75:13: executing "_default/rss.xml" at <$categories>: range can't iterate over Transport
ERROR 2022/05/12 15:41:20 render of "term" failed: "/Users/jess/Documents/GitHub/jayeless.net/layouts/_default/rss.xml:75:13": execute of template failed: template: _default/rss.xml:75:13: executing "_default/rss.xml" at <$categories>: range can't iterate over Transport
Error: Error building site: failed to render pages: render of "section" failed: "/Users/jess/Documents/GitHub/jayeless.net/layouts/_default/rss.xml:75:13": execute of template failed: template: _default/rss.xml:75:13: executing "_default/rss.xml" at <$categories>: range can't iterate over Food