Skip to main content
ertius.org

Hugo Archetype Date Is Not a Date

So, I was just reminded of archetypes in Hugo and it occurred to me that I could just use that for my template instead of a crazy script. The obvious attempt:

title: "{{ .Date.Format "2006-12-01" }}: {{ replace .Name "-" " " | title }}"

gave a rather exciting error:

Error: failed to execute archetype template: template: archetype.md:2:16: executing "archetype.md" at <.Date.Format>: can't evaluate field Format in type string: template: archetype.md:2:16: executing "archetype.md" at <.Date.Format>: can't evaluate field Format in type string

which led me to this forum post, explaining that .Date is a string, not a date. So, the correct template is:

title: "{{ now.Format "2006-01-02" }}: {{ replace .Name "-" " " | title }}"

Which only works for today, which is a bit unfortunate.