Wowchemy-hugo-modules: Add support for YAML based talks ("GroupByParamDate time_start" generates a "runtime error: index out of range")

Created on 1 Jun 2018  路  5Comments  路  Source: wowchemy/wowchemy-hugo-modules

I created a new talk page (with hugo new talk/name.md), which was automatically formatted with a YAML frontmatter (rather than TOML, as used by default in the exampleSite). This created a weird effect in the ordering of talks: the YAML one was listed after the others. So I decided to convert all talks' frontmatters to YAML. When the last one was converted, Hugo would not build the site anymore, running into an error:

Failed to render "theme/section/talk.html": runtime error: index out of range

After searching a lot, I found this closed issue in Hugo. The error thus comes from layouts/partials/section/talk.html, line 15:

{{ range .Data.Pages.GroupByParamDate "time_start" "2006" }}

In YAML frontmatter, the time_start field is interpreted as a string, rather than a datetime field, which generates this error.

I have tried everything I could think of (changing the format of the time_start field, changing the layout page to first transform the variable into a datetime field (time .variable), but could not find a way to make it work. Maybe you are more familiar than I am with the Go syntax to make the time .variable conversion work before running range GroupByParamDate?

upstream

Most helpful comment

i've moved to Hugo and think that metadata should be kept in YAML, since it is recognized and used not only by GitHub, but also by so many markdown editors. so count on me on YAML compatibility maintenance!

All 5 comments

Academic is designed and tested for use with TOML as per the documentation and example site. If someone adds support for YAML based talks, I'll consider merging it in though.

@gcushen It makes sense. It is not like if YAML was really bringing something new to the table (besides highlighting in my editor ;-)), so I'll revert everything to TOML I think. Feel free to close this issue!

I do find it interesting that the start and end date/time fields for talks are the only places where formatting as a string鈥擾i.e._, using quotation marks鈥攃auses such an error. It makes no difference (that I can tell) in any of the other date/time fields. I figured it out because I had them all set in quotes, out of ignorance, and it was only this case that broke Hugo.

i've moved to Hugo and think that metadata should be kept in YAML, since it is recognized and used not only by GitHub, but also by so many markdown editors. so count on me on YAML compatibility maintenance!

There are 3 options to support YAML front matter for talks:

  • group talks on the talk archive page by date instead of time_start. This should generally be a good enough approximation - it assumes that the talk page is first published in the same year that it is presented
  • do not group talks on the talk archive page
  • wait for go-yaml to fix the bug described here (no ETA) and then wait for Hugo team to integrate the fix

Let's go with the first option for now and re-evaluate later on if it's still the best option.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pjox picture pjox  路  4Comments

somnathrakshit picture somnathrakshit  路  3Comments

chris-prener picture chris-prener  路  3Comments

jacebenson picture jacebenson  路  3Comments

eduardohenriquearnold picture eduardohenriquearnold  路  4Comments