I’m using Zettelkasten formatted IDs in the front matter of some pages on my site. The ID format is intentionally quite compact since I must often write them by hand, but the format still allows the ID to inform about hierarchy and which pages are related.
Each such page has a param in the front matter labeled tdgid. Sample pages have tdgid values like:
I’m currently ranging over all such pages successfully using:
range (where .Site.Pages ".Params.tdgid" "!=" nil).ByParam "tdgid"
This is almost what I want, but it’s lexically sorting RT6a10 and RT6a11 before RT6a2.
The simplest “solution” would be to always use two places for each field within the string, but since I handwrite these often I’d like to keep them as short as possible. I suppose “live with the broken ordering” is an even simpler solution.
My Go and Hugo skills are anemic at best. I’m hoping some kind soul with more experience than me could offer a suggestion and save me from a few hours of hacking.
There is currently no provision in Hugo for a “natural” sort. In my experience natural sort mechanisms are uncommon outside of file managers, so I generally plan accordingly (i.e., zero padding to n places).
Yeah, I’m thinking along the same lines, but I’d rather not store the padded values in the front matter. I’d rather that humans never see the padded versions (to prevent confusion).
I’ll look into building up a map of padded IDs and paths to range over, and then use GetPage with each.
Padding isn’t as simple as prefixing the entire string with a padding character, though. I’ll need to pad each field within the string (each time it switches from alphabetic to numeric). I know I’ll never have more than, say, five levels of hierarchy, and will never need more than three characters in each field. I’m currently investigating replaceRE to add the padding.