Inserting lastmod on post content

Is there a way to insert the lastmod (git) on a post content? Something like {{ .Lastmod.Format "02 January 2006 @ 15:04:05 MST" }}, but instead of on a template, on the content of a post. Is that possible?

The use case use is, I want to be able to edit a post, adding a note on the post itself that has been edited at a certain timestamp, and not having to add the timestamp manually.

you dont have to set a date in frontmatter. You may use the git commit date. see Configure front matter

if you want something special you may code a custom shortcode.

I have it configured. When I am after is:

---
Frontmatter here
Frontmatter here
Frontmatter here
--- 
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec imperdiet at justo eu luctus. Ut iaculis quam sit amet justo molestie sagittis. Fusce imperdiet leo ac lacus pretium, ac efficitur ipsum lobortis. Mauris nunc lorem, egestas in purus in, lobortis placerat lacus. Nam iaculis commodo suscipit.

**Updated:** {{ insert_lastmod_here }}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec imperdiet at justo eu luctus. Ut iaculis quam sit amet justo molestie sagittis. Fusce imperdiet leo ac lacus pretium, ac efficitur ipsum lobortis. Mauris nunc lorem, egestas in purus in, lobortis placerat lacus. Nam iaculis commodo suscipit.

with the format you will need a shortcode

a custom shortcode: layouts/_shortcodes/lastmod.html

code:

.Page.Lastmod.Format "02 January 2006 @ 15:04:05 MST"

call it {{< lastmod >}}

as you said, I assume gitinfo is enabled and frontmatter dates are configured.

— guess you are aware that using the shortcode multiple times on the page will show the same date for each

1 Like

Excellent! This works as I wanted. I was trying with a shortcode already, but was placing the wrong content in it. Thank you much!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.