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: "http://server.com/file-doc.7z"
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: "http://server.com/installer-x64.exe"
installer_x86_md5: "md5123"
installer_x86_sha256: "sha256"
installer_x86_size: "17MB"
installer_x86_url: "http://server.com/installer.exe"
package_x64_md5: "md5123"
package_x64_sha256: "sha256"
package_x64_size: "9.4MB"
package_x64_url: "http://server.com/package-x64.7z"
package_x86_md5: "md5123"
package_x86_sha256: "sha256"
package_x86_size: "9.9MB"
package_x86_url: "http://server.com/package.7z"

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:

files:
  - title: "Installer (x86)"
    type: "installer"
    size: "17MB"
    url: "http://server.com/installer.exe"
    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.

Hello,

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

params:
  files:
    - 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 https://github.com/spf13/hugo/blob/master/hugolib/page.go#L413. 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 https://github.com/spf13/hugo/pull/1225. I need it badly so if someone have some time to review it i would be grateful :wink: