Discussion about signaling published/unpublished documents with an icon in Sanity.io
14 replies
Last updated: Jul 6, 2021
A
Another question about published/unpublished documents. Is there a way to signal to the users that a given document is un/published? It would be really helpful to include an icon for that in the document list.
Jul 5, 2021, 2:02 PM
About halfway down this page it shows one way you can do that: https://www.sanity.io/docs/previews-list-views
Jul 5, 2021, 2:24 PM
A
Cool, but this is not specifically for un/published statuses right?
Jul 5, 2021, 3:14 PM
The
which renders:
_idof a document begins with
draftsif it is not published. So, this works:
preview: { select: { title: 'title', theId: '_id' }, prepare(selection) { const {title, theId} = selection const isDraft = theId.substring(0,5) == 'draft' ? 'đź‘·' : 'âś…' return { title: title, media: <span style={{fontSize: '1.5rem'}}>{isDraft}</span> } } }
Jul 6, 2021, 12:32 PM
A
Cool! I’ll try it, thanks
Jul 6, 2021, 12:32 PM
A
Where do did you get the icons from?
Jul 6, 2021, 12:38 PM
A
So technically, a “draft” state can mean three things: 1. you have modified an existing document (that still can be “live”), 2. you have created a new one or 3. you have unpublished it, correct?
Jul 6, 2021, 12:49 PM
A document, identified by
What is immediately visible in the document editor (and exposed in API if published) is identified by the
_idis either in a published or unpublished state. If it's not published the
_idwill start with `drafts.`(and it won't be exposed in api)
What is immediately visible in the document editor (and exposed in API if published) is identified by the
_idand a revision, under
_rev. As you change among various historical versions of your document, the
_revchanges for each.
Jul 6, 2021, 1:56 PM
A
Oh so if you start and modify an already published document, that document will be unpublished automatically?
Jul 6, 2021, 1:57 PM
There are two places you can click to see this in action...go to a document and fiddle around - publish, unpublish, edit, go up to "current version" and choose a prior revision. As you do so, go each time to "inspect" and you can see the
_revand
_idvalues changing
Jul 6, 2021, 1:59 PM
A
Ok, I see. So there is no direct property to check for only published/unpublished
Jul 6, 2021, 2:00 PM
A
Yep, gotcha
Jul 6, 2021, 2:00 PM
But I think that's the case since in the docs:
https://www.sanity.io/docs/drafts
Drafts are not available to the public API, but can be accessed using an authenticated client or using an access token. Sometimes you therefore might need to filter drafts from your queries. You can do this by adding the following filter:
*[!(_id in path('drafts.**'))] // _id matches anything that is *not* in the drafts-path
https://www.sanity.io/docs/drafts
Jul 6, 2021, 2:04 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.