How to Add Last Modification Date in Hugo

Hongtao Hao / 2020-06-09


Earlier, I thought this must be a difficult undertaking, but later I found this is relatively easy to accomplish.

The solution was here , posted by funkydan2.

According to Hugo’s documentation on Page Variables , there are two ways to specify last modification date. One way is to specify the .Lastmod in a content’s front matter. That is to say, while you are specifying the title, date, author, slug, etc., you also specify lastmod. The second way is through .GitInfo.

I recommend using the .GitInfo . This method is better because it is automatic.

In your single.html within layouts -> _default, you simply add this line of code:

<p>Last modified on {{ .Page.Lastmod.Format "2006-01-02" }}</p>

Then, in your config.toml, you simply add enableGitInfo = true.

You can check my single.html and config.toml setting for a reference.

Please note that this is just an example. There are many ways to achieve the goal. You are encouraged to do it in your own way (if you have enough time…).

Last modified on 2020-06-24