I have a fairly large (growing) YAML resource which is used by a shortcode. I quickly put together a POC code that “just works”, but the issue is that it is traversing the whole YAML to find the needed node, then traverse it further, like so:
{{ $p := where $data "id" $pid }}
{{ range $p }}
{{ $.Store.Set ... }}
{{ if $sid }}
{{ $sdata := (index . "sec" )}}
{{ $s := where $sdata "id" $sid }}
{{ range $s }}
{{ $.Store.Set ... }}
{{ end }}
{{ end }}
{{ end }}
There is a “primary” and “secondary” levels to the YAML data ($pid
and $sid
- if any - is passed into the shortcode), but ranging everything is very inefficient. There’s multitude of these shortcodes on every page. It’s noticeably hogging the site generation.
With a usual paradigm I would make these into maps where IDs are the keys, but I am not sure how to approach this with Hugo templating. I have the feeling this is a use case for hugo.Store
, but I am not sure how to prepare it for the shortcode calls to access it only when ready.
Thanks for any help pointing me in the right direction.