On a blog site built with Hugo, I was stuck for a while on a problem where the “Last modified” date of each post was not displayed correctly.
Every post ended up with the same date, and the actual update date of each post was not reflected.
In this article I explain the cause of the problem and how to solve it.
My environment uses Github and Cloudflare Pages.
Symptoms
The “Last modified” date shown in the post metadata was the same date on every post.
For example, it was displayed like this:
<span class="post-meta">Posted on December 3, 2025 (Last modified on December 4, 2025)</span>Even though each post really did have a different update time, the same “Last modified” date was displayed on all of them.
Causes
There were two causes of the problem.
1. The priority of the lastmod setting in hugo.toml
In the [frontmatter] section of hugo.toml, the lookup order for lastmod was as follows:
[frontmatter]
lastmod = ["lastmod", ":git", "date", "publishDate"]With this setting, if lastmod is specified in the front matter, it takes priority over the git commit information (:git).
As a result, the last modified date that should have come from the git commit history was not reflected correctly.
2. Shallow clone on Cloudflare Pages
When Cloudflare Pages performs a build, it does a shallow clone (--depth=1) by default.
With a shallow clone, only the latest commit and the files related to it are fetched; the past commit history is not.
In that state, commands such as git log do not work correctly, and Hugo’s GitInfo feature does not work properly either.
That meant the last modified date could not be obtained from each file’s git commit history.
Reference: HugoのGitInfo機能をGitHub Actionsで使う - KOTET’S PERSONAL BLOG (in Japanese)
Solutions
1. Change the hugo.toml setting
Change the lastmod setting in hugo.toml so that :git comes first:
[frontmatter]
lastmod = [":git", "lastmod", "date", "publishDate"]This makes the last modified date obtained from the git commit history take priority.
2. Change the Cloudflare Pages build command
In the Cloudflare Pages dashboard, change the build command as follows:
Where to set it:
- Cloudflare Dashboard → Pages → select the project
- Settings → Builds & deployments
- Change the Build command
Before:
hugo --gc --minify -b $CF_PAGES_URLAfter:
git fetch --unshallow && hugo --gc --minify -b $CF_PAGES_URLWith git fetch --unshallow, the full git history is fetched before the build and then hugo is run.
This lets Hugo’s GitInfo feature work properly and obtain the last modified date from each file’s git commit history.
Verification
After the configuration change, the “Last modified” date of each post was displayed correctly, like this:
post-a.md→ committed on January 1, 2024 → Last modified: January 1, 2024post-b.md→ committed on March 15, 2025 → Last modified: March 15, 2025
Because :git picks up a different commit date for each file, all the posts no longer end up with the same date.
Summary
The problem of Hugo’s Last modified date not being displayed correctly was solved with the following two configuration changes:
- Put
:gitfirst inhugo.toml - Run
git fetch --unshallowin the Cloudflare Pages build command
With that, an accurate last modified date based on each post’s git commit history is now displayed.
I had been convinced that I would need to fix something inside the program, so I did not expect it to be solved by the Cloudflare Pages build command alone.