Would anyone be interested in such a feature? Unfortunately, my go skills and my understanding of the hugo codebase are close to zero, so I think I would need help to implement something like that
If the integrated menu system can allow me at least to have the order of items respected without using the weight param, this will allow me to ditch my over-engineered data-files menu system which I’ve already begun to simplify.
Note: i don’t want to set the URL here, because I do it in the translation files directly, hacking around with plurals and singulars. But I want my menus to be the same across languages.
Unfortunately no (i speak very little regex ^^). I don’t see what in your template would reorder the menu properly. Could you maybe explain for me please?
I embed the menu weights as part of menu names. That way, I need zero menu config in my site config.
The menu names are are “0.search”, “1.foo”, and so on. I rarely add/remove menus, so I don’t need to renumber the weights.
Then when .Site.Menus is looped, it will go through those menus in alpha(numerical) order, and I get the menu order as expected (set by the weight prefixes).
About the editing flow: In my flow, I write all posts in tree structure. So the menu name set at the tree node propagates to the children nodes. So I need to set the menu name just once. An alternative would be to have some sort of script to set the menu names.
But all of that would be a huge overkill, and setting the menu weights in the site config would eventually be better… and so I striked out that suggestion.
I don’t use children menus and based on the logic in that template, I’d be surprised if it would “just work”. But it should be easy to implement… once you “get” the map structure of .Site.Menus (see this for example – Search for foo" on that page, yes with that ending double-quote). In the template, you would then need to skip the menus that have .Parent defined… and if .Children is defined, you do the same looping in there… I hope that makes sense.
So I got around to implement it as you suggested @kaushalmodi, and it works like a charm, thank you! Here’s my template now, and my config file. It works perfectly thank you so much!
Now i guess I’m left with my second question being, can we make it less verbose? When I used data templates I used to write my menus like so:
I don’t use the site config to manage menus. I just set the menu attributes from each page’s front-matter.
That said, I don’t use menus with the kind of nesting you do (my “most complex” menu is this, in the left). I can certainly see the value in what you propose if doing menu management from the site config.
As I mentioned earlier, I organize my site content in tree fashion (Org mode), so it looks like this to me:
From that example, the pink headings (each of which export to a separate Hugo content file) are nested under the green headings. So all pink headings under the “Enhancements” green heading will have their menu set to “6.enhancements”.