Set date in front matter from `hugo new` command

Heya folks! :wave:

I’m trying to set the date front matter in a hugo new command, but I’m just can’t recall how it works.

The idea is that I would do something like hugo new /2008-01-15-daily/index.md --another-thing=2008-01-15 and using archetypes/default.md it would produce, at content/2008-01-15-daily/index.md:

---
title: "Daily entry for 2008-01-15"
date: 2008-01-15
---

How do we pass commandline parameters to front matter, via archetypes? :thinking:

Option 1

config.toml

[frontmatter]
date = [':filename', ':default']

See:
https://gohugo.io/getting-started/configuration/#configure-dates

:filename
Fetches the date from the content file’s filename. For example, 2018-02-22-mypage.md will extract the date 2018-02-22. Also, if slug is not set, mypage will be used as the value for .Slug.

Option 2

archetypes/default.md

title = '{{ replace .Name "-" " " | title }}'
date = {{ or (os.Getenv "HUGO_DATE") .Date }}
draft = false

Then create a new page with

HUGO_DATE=2008-01-15 hugo new foo.md
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.