Retain order of front matter with Hugo Convert

I tried the hugo convert toTOML --unsafe flag and two issues happened. First, the order of the front matter is jumbled up rather than following the format I use e.g. I use title, url, date, lastmod, summary bur it becomes jumbled up into something like date, description, lastmod, summary, etc. Second, it leaves a blank line between the last front matter entry and the closing +++. Is there a way to avoid this from happening?

Target format Resulting order Blank line before closing delimiter Comments retained
JSON Alphabetical No No (not supported)
TOML Alphabetical Yes (see this issue) No
YAML Alphabetical No No

I’m pretty sure that retaining the original order would be complicated/expensive, and I’m not sure it’s the right thing to do. When you use convert on your content, the resulting order will be consistent (alphabetical) across all pages; it’s a nice way to clean things up, spot missing values, etc.

1 Like

This explains it. Let me think a bit on whether I need to do the conversion until the delimiter issue is fixed.

As a time being, until the problem is officially fixed, you can delete the blank line after the conversion. This should be easy to automate.

Under Linux, for example, you could use the command sed '/+++/,/+++/{/^[[:blank:]]*$/d}'. article.md. This searches for +++ in the file Article.md and deletes all blank lines in between two matches.

Of course, you would have to put the command in a loop so that all Markdown files are automatically processed.

The above command outputs the changed content of the file, but does not change it. So you can test if everything is correct. To change the files directly, you must enter the parameter -i directly after sed.

However, the command has a disadvantage. The entire file is searched. If the string +++ is found under the front matter area, the empty lines are also removed there.

The delimiter issue is fixed in v0.104.3.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.