Choose Where Hugo Gets a Page's Last-Modified Date
An “updated” date is only useful when it means something. Hugo can read it from front matter or Git history, but those sources answer different questions.
Manual Date Management
Set date and lastmod in front matter when you want editorial control over both values:
---
title: Advanced Web Development Techniques
date: 2024-01-15T09:00:00+00:00
lastmod: 2024-01-26T14:30:00+00:00
url: /web-development-guide/
---
This is the approach I prefer for articles. A spelling correction does not necessarily deserve a new visible date, while a substantial technical revision does. The author can make that distinction; a file timestamp cannot.
In the template, show “Updated” only when lastmod is later than date. Otherwise the repeated date adds noise.
Git-Based Date Tracking
Git history is useful when manually maintaining lastmod is unrealistic. Enable Git information and tell Hugo which sources should take priority:
enableGitInfo = true
[frontmatter]
lastmod = ["lastmod", ":git", "date", "publishDate"]
Here Hugo first uses an explicit lastmod, then the relevant Git timestamp, followed by date and publishDate.
The tradeoff is that any committed change can move the Git-derived date, including formatting or metadata maintenance. For documentation that may be fine. For a public article, I would keep explicit dates authoritative and use Git only as a fallback.
Enjoyed reading this?
If you found this article helpful, consider supporting my writing. Every little bit helps keep this blog going.
Related articles
- Customizing Hugo’s RSS Feed
Adjust Hugo RSS titles, descriptions, content, and section filtering while keeping the generated feed valid and easy to discover.
- Organizing Hugo Content With Tags and Categories
Organize Hugo content with a small, deliberate set of tags, categories, or custom taxonomies that lead to useful archive pages.
- A More Useful 404 Page in Hugo
Turn Hugo's 404 page into a useful route back to the homepage, search, or content visitors may have wanted.