When building documentation and blog sites in fields where recency is important (like technology), it’s useful to display the last updated date of a post. While not supported at the framework level, last edited labels are easy to implement with Contentlayer’s computed fields.
Getting the last updated date
Contentlayer document types give us reference to the raw source file, which we can use to get the last modified date using Node functions.
Defining a computed field
This helper can be used to define a lastEdited field on the Post document type which will resolve at build time.
Using the lastEdited field
After generating types again the lastEdited field is available on the Post type and can be rendered on posts. The field is a Date object, so it can be formatted using a library like date-fns.