Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Finding first and last published dates on a web page using custom fields and actions.

4 replies
Last updated: Jun 15, 2023
Hi. If I want to show when a document was first published and last published on a web page how would I find that info? For last published, I guess _updatedAt is the correct timestamp, but _createdAt might not be the same as first published. I Have tried getting the transactions from the history api, but I'm not sure how to retrieve first published from the ndjson that is returned...
Jun 14, 2023, 8:28 AM
I found this: https://www.sanity.io/schemas/make-a-field-read-only-after-publishing-once-d87bf5f6 So I'm thinking the the solution is to create a custom "publish" action that sets a "firstPublished" field the first time
Jun 14, 2023, 8:43 AM
Yes, you’re correct! You’d need to create your own fields for this.
Jun 14, 2023, 4:24 PM
This led me to reading the docs on custom actions, and my case is exactly what is documented :D
Jun 15, 2023, 6:57 AM
I love it when that happens!
Jun 15, 2023, 5:09 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?