Why last modification of website pages is today?

minherz
2 min readApr 3, 2024

--

I already boasted that I’ve started my own blog website. I write posts in Markdown and commit changes to Github which automatically builds and publishes it. It works fantastic. It is quick, automatic. But there is one small caveat that puzzled me for some time. I configured to show the last modified date of the post to be displayed and also order the posts in the main page based on the last modified date. And each time the website is build with Github actions ALL posts has the same last modified date which is the date of the build.

Apparently, when Hugo is configured to use Git when it determines the last modified date, it executes git log -1... command. Since my Github workflow used actions/checkout@v4 as you can see in hundreds of code samples:

    - name: Checkout source code
uses: actions/checkout@v4

the code for only the last commit was fetched. It makes the git log command to return the same date for, well, all files. The fix was simple and straigthforward. I just added fetch-depth argument to instruct the checkout action to fetch the whole history and got my last modified date as expected:

    - name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0

The downside is that this argument brings all history. So, when my repo will become really big and the history will count hundreds of thousands or even millions commits, the build process will be very slow and I will need to review either the build process or the way I use and display the last modified date.

Until then … I am happy.

See more about building a blog website using Hugo on my blog.

--

--

minherz
minherz

Written by minherz

DevRel Engineer at Google Cloud. The opinions posted here are my own, and not those of my company.

No responses yet