Change Hugo Default lastmod Date


Today I found that even if I set lastmod date manually in my hugo post front matter, the content last modified date still pulls from .GitInfo.AuthorDate, Which is a different than my expectation. If lastmod is set, I thought it should have the highest priority.

Dug a little in hugo documentation, The .Lastmode variable is for the date the content was last modified and it pulls from the lastmod field in a content’s front matter. The default behavior is:

  • If lastmod is not set, and .GitInfo feature is disabled, the front matter date field will be used.
  • If lastmod is not set, and .GitInfo feature is enabled, .GitInfo.AuthorDate will be used instead.

What if lastmod is set and .GitInfo feature is enabled? This is a common combination. In the configure front matter section of config.toml file. The default configuration for lastmod is:

1
2
3
4
[frontmatter]
  ...
  lastmod = [":git", "lastmod", "date", "publishDate"]
  ...

The order of lastmod array explains why .GitInfo.AuthorDate has higher priority than lastmod. I added follow to the config.toml then last modified date works as expected:

1
2
[frontmatter]
  lastmod = ["lastmod", ":git", "date", "publishDate"]