Hello,
I want to implement a feature that allows me to specify a last modified date in the front matter for each post, which will then be displayed in the post. I tried adding #+lastmod in the front matter, which works, but when it’s missing, it falls back to the modified value and the conditional still executes. To fix this, I added this into hugo.toml:
[frontmatter]
lastmod = ['lastmod'] # no fallback values
Then in the template I can use:
{{ with .Lastmod }}
<div class="post-lastmod">
<p>Last modified on:
<time datetime="{{ . | dateFormat "2006-01-02" }}">{{ . | dateFormat "January 2, 2006" }}</time>
</p>
</div>
{{ end }}
Considering that modifying the hugo.toml file in this case is more of a custom option, a deviation from the default behavior, I’m thinking that using the lastmod option might not be the best choice. I’m curious: for those of you who have implemented such a feature, what name do you typically use in the front matter for this purpose?
By using the default value lastmod: I also need to add:
[frontmatter]
lastmod = ['lastmod']
Otherwise, the while loop executes even if the lastmod is not present in the front matter. If it’s present it results in a valid date (the date I specified) but if not, it ends up with an empty date value.