Use an array of structured frontmatter in YAML

Hello folks,

I’m trying to build a section template that allow me take a list of files and provide download links for them.

Each content file will have different combinations of those links. At this time, I’m doing something like this:

docs_url: ""
docs_size: "4.8MB"
docs_md5: "md5123"
docs_sha256: "sha256"
installer_x64_md5: "md5123"
installer_x64_sha256: "sha256"
installer_x64_size: "17MB"
installer_x64_url: ""
installer_x86_md5: "md5123"
installer_x86_sha256: "sha256"
installer_x86_size: "17MB"
installer_x86_url: ""
package_x64_md5: "md5123"
package_x64_sha256: "sha256"
package_x64_size: "9.4MB"
package_x64_url: ""
package_x86_md5: "md5123"
package_x86_sha256: "sha256"
package_x86_size: "9.9MB"
package_x86_url: ""

As you can see, I have different combinations for items, which makes really hard to stay DRY defining those download elements.

I was looking into ways to have a more structured version:

  - title: "Installer (x86)"
    type: "installer"
    size: "17MB"
    url: ""
    md5: "abc123"
    sha256: "sha256"
  - title: "Binary (x86)"
    type: "binary"
    url: "..."

But Hugo (I believe is due YAML parsing support in Go) refuses to recognize that structure and .Params.files returns empty.

Do you suggest any alternative to avoid having to define code for all the links?

Thank you in advance for your suggestions.


I believe I found the error and a naive workaround, which is place files inside params:

    - title: ...
    - title: ...

Thing is that to iterate over this I need to do .Params.params.files, which makes me feel I’m doing something wrong.

Any advice will be appreciated.

Thank you.

I think this is caused by It sets front matter values but it expects the value []interface{} type has string type elements though it actually has map[interface{}]interface{} elements in your case so I think something code fix is needed to make Hugo work as you expect. Or, yes, as your workaround, if there is something intermediate structure, it would work.

I have made a pull request I need it badly so if someone have some time to review it i would be grateful :wink: