Set frontmatter "date" (and other) by command line

I use the frontmatter date to show publishDate in my articles. Might it be possible to have a feature for commandline manipulation of frontmatter? I’m creating a new article but writing on it sometimes for several days before publishing.

Let’s think aloud: Possible syntax:

hugo frontmatter path/to/ [--secure] date NOW=default|Unix-Timestamp|Go-Time
hugo frontmatter path/to/ [--secure] PARAM "VALUE"

This function should overwrite the given value in frontmatter, it could print a former value, if there’s one set (by adding the former value to output it’s possible to do a reset).

By thinking longer about and wirting here… Let’s give it a flag --secure to preserve former values.

1 Like

Hi @phi - There are tools that can do that, though, like sed, awk and so on.

I’m working on different platforms (windows, android (by termux) and unix-like) and it would be very cool to have the ‘one binary without dependencies’ doing that kind of stuff right with Hugo.

Windows is some kind of pain in the … - as far as I’m not using the PowerShell.

But your solution works fine on others - thanks! I should learn go, the undraft function should be very similar to what I like to have.

Yeah, that would throw a wrench in it. But, apparently with Windows 10 you can now run an Ubuntu shell?

Wild guessing, but, you could make your own little util for it:


I’m using toml - so it’s a bit less complicated to do what I want. For now a litte function in my .bash_profile does the job very well

function setdate() {
  sed -i "/^date/d" $1;
  sed -i "3idate = \"$(date +%Y-%m-%dT%H:%M:%S%:z)\"" $1;


$ setdate path/to/

Running in an MinGW-env on Windows 10 works fine. Solution with a fast-ring to get a “native” Ubuntu shell is not applicable - it’s like using a alpha-version on production-system.

Now having a solution working for me and I will have a look at the code of hugo - maybe I can find a more general solution to be built in and working will yaml, toml, … afk learning Go :wink:

Thanks for your help!

MEMO to myself: RTFM!
The undraft option gives it in its long description:

Undraft changes the content’s draft status from ‘True’ to ‘False’ and updates the date to the current date and time. If the content’s draft status is ‘False’, nothing is done. (undraft.go, line 19f)

seen this

would be fantastic to have this type of functionality in hugo

or this written in portable GO

sorry for kicking the old post