I’m a new Hugo user with little knowledge of it. I’ve been playing around with it and some themes for the last few days. I’ve more or less settled on a theme (I think someone did a really good job), but I’d like to slightly tweak it here and there, and I’m trying to do that by looking at other themes that have the configurations I want. However, I’m currently stuck.
TL;DR:
My theme already sets
<meta property="article:published_time" content="2017-09-13T08:38:00+02:00">
<meta property="article:modified_time" content="2023-09-13T08:38:00+02:00">
and
<meta itemprop="datePublished" content="2017-09-13T08:38:00+02:00">
<meta itemprop="dateModified" content="2023-09-13T08:38:00+02:00">
very nicely out of the box. If lastmod isn’t defined in the frontmatter, it uses date for the meta tags as it should. Perfect!
However, the page itself currently only outputs date, but not lastmod. And I would like it to display something like “Posted on 9 Sep 2017, last updated 9 Sep 2023”. I’m able to to that with
<time datetime='{{ .Date.Format "2006-01-02" }}' pubdate>
{{ .Date.Format (default "2006-01-02" .Site.Params.dateFormat) }}
</time>
Last updated
{{ .Lastmod.Format (default "2006-01-02 15:04:05" .Site.Params.dateFormat) }}
Most of my blog posts don’t contain lastmod, though. The question is, how do I make the output of
Last updated
{{ .Lastmod.Format (default "2006-01-02 15:04:05" .Site.Params.dateFormat) }}
dependent on whether lastmod is set in the frontmatter?
Any help or pointers would be greatly appreciated.