Frontmatter dynamic date

In Hugo file I can set date in the frontmatter date: 2022-01-30 but can this be automated for example on each modification when I save the file can it update the date using something like {{.now}} etc.

I try few things shown on this page.

the purpose of this is when ever I edit a post and save in code editor Hugo can update the sitemap showing that the post was modified on certain date I realise that It is hard to keep track of this manually.

if it is not currently possible can I request it as a feature in a new Hugo release maybe.

thanks in advance for taking the time.

If you’re using Github, this

might help

1 Like

thanks @chrillek thats interesting, so Hugo can make use of git info. I am not sure I fully understand the GitHub part does it only work with GitHub? the code editor do have git info on a local folder can Hugo make use of this or it will work exclusively with GitHub.

It works with any Git repository. Your code editor is NOT hugo so anything your editor does has nothing to do with Hugo. VSCode has plugins that update your lastMod frontmatter to the current date. Git has the file date that your latest commit has.

Hugo however will never take into account whatever editor you are using. It’s a static website generator, not a content management system. It will take whatever you give it and date and lastmod are frontmatter values it would take into account with the proper layout files to sort things.

1 Like

thanks for the quick response @davidsneighbour

would you be kind enough to share the name of the

I currently use:

  • Hugo helper by Ruslan Nasonov
  • Hugo Language and Syntax support by Budparr
  • Hugo Snippets by fivethree

There is a plugin that I think might be overkill in the beginning (still trying to learn the ropes with it) called “Front Matter” (which is basically your CMS for Hugo (or any other static site generator) inside of VSCode. Have a look at it (but backup your files before). Lots of configuration options in there, one of them is automatic update of your frontmatter lastmod tag.

The one I am using (manually) is Insert Date String - Visual Studio Marketplace

1 Like