Home → The Classics → Farai's Codelab
Ok, How Do I Get These Bloody Dates To Work Properly In Hugo?
Published:
Honestly, this post is more for me than for you so don’t expect to find it useful. If you do then I’ll be shocked. If you want to see what I settled on, jump to the end.
This is how I want dates to work in Hugo:
Lastmod
for when the post was last modified (which is when I’ve made noticable changes),PublishDate
is when a post was published, reposted or the scheduled date of publishing, andDate
is when a post was first published.
Here’s what I want to do
- I’ve created a new post and I want to publish it immediatley—
PublishDate
orDate
works here. - I want to update the post in 1, so I set a
Lastmod
date. - I want to republish an old post, so I’d use
Date
for the inital date the post was published,PublishDate
for when the post was republished and maybe aLastmod
for the last time I updated a post. - Some things don’t have publish dates per say since they’re constantly updated. Think the /now page.
This all sounds easy enough but the issue is getting it to show up on a web page.
Let me try a truth table instead:
LastMod | Date | PublishDate | What to show |
---|---|---|---|
T | T | T | PublishDate is Reposted, Date is initially posted, Lastmod is when it was last updated |
T | T | F | Throw Error |
T | F | F | Just show Lastmod date |
F | T | T | PublishDate is Reposted, Date is initially posted |
F | F | T | Just show PublishDate |
T | F | T | PublishDate is Published, Lastmod is the updated date |
Much clearer now, though the issue is how to sort posts in a list.
My Solution for Now
This is what I’ve settled on:
- PublishDate is the date a post was actually published/republished,
- LastMod is when the post was last modified
- InitialDate is when the post was initially posted
- Date is the post’s date in order of
Date
,PublishDate
andLastmod
I then add this to my config file:
frontmatter:
publishdate:
- publishdate
- date
date:
- date
- publishdate
- lastmod
lastmod:
- lastmod
Using this seems to work for now. I’ll see how it works as I go along.