Date in Updated Posts
| Updated: website, hugoA small update. I’ve added | Updated: 2024-10-28
after the date in a post if it is updated and pick it up from the git commit. I’m not happy with how it looks right now, but it’s ok.
How is it done?
First we need to enable GitInfo
in our config file hugo.yml
:
enableGitInfo: true
Next we have the actual code which will display this in the single.html
. For me, this is in layouts/partials/metadata.html
.
In the top I define the variables:
{{ $date := .Date.Format "2006-01-02" }}
{{ $lastmod := .Lastmod.Format "2006-01-02" }}
And to show the date:
{{ $date }}
{{ if ne $lastmod $date }}
| Updated: {{ $lastmod }}
{{ end }}
Right now I need to add lastmod:
with the same date of the post to not show the date if it’s the same day. If I comment it out it will show for some reason. I didn’t care that much about to start dig for a solution.
How it looks
This post is updated, just to see how it looks. It doesn’t look good, but I have no better solution to it right now.