I am designing a page based on the hugo docs “theme” with a two-level menu.
I am fine with defining menu items through both frontmatter and config.toml.
I do want to define menu items depending on the content in more sophisticated fashion, like:
I have an archetype “release” and I want to create menu entries for the 3 latest such releases.
AFAICS this is neither possible through the frontmatter nor though config,toml.
I have tried hacking it into the menu template of the hugo docs, and I can get it to look okay with something like this:
{{ if eq .Identifier "releases" }}
{{ range first 3 (where $.Site.Pages "Type" "releases").ByTitle.Reverse }}
<li><a href="{{.RelPermalink}}">v{{ .Title }}</a> </li>
{{ end }}
{{ end }}
However, the menu folds again upon clicking it. To avoid that I would need to treat these additional child menu nodes just as all the others are treated:
{{ range .Children }}
<li{{if $currentNode.IsMenuCurrent "main" . }} class="active"{{end}}><a href="{{.URL}}">{{ .Name }}</a> </li>
{{ end }}
Unfortunately, I cannot see how to transform these into proper tree nodes in a go template. I should probably mention that I have no clue of Go as a language. Anyone to the rescue? TIA!