packages/sanity/src/core/scheduled-publishing/README.md
Schedule your content for future publication and organise upcoming releases – no custom tasks or serverless functions required!
This plugin uses Sanity's [Scheduling API][scheduling-api] which is available to customers on [Growth or higher plans][pricing].
This feature is included by default in your studio.
This will automatically:
To change the date formatting used when creating and editing schedules, pass a valid date-fns formatted token as an option.
defineConfig({
...yourConfig,
scheduledPublishing: {
enabled: true,
// E.g. 12/25/2000 6:30 AM, make sure to specify minutes and hours if you are specifying a custom format.
inputDateTimeFormat: 'MM/dd/yyyy h:mm a',
},
})
If left unspecified, this plugin will default to dd/MM/yyyy HH:mm.
This example assumes [you've customized your document actions][document-actions] and would like to only show the Schedule button on movie documents only.
The Schedule document action allows users to both create and edit existing schedules directly from the form editor. It is added to all document types by the plugin, so you should remove it from types that should NOT have it.
import {scheduledPublishing, ScheduleAction} from '@sanity/scheduled-publishing'
export default defineConfig({
// ...
plugins: [scheduledPublishing()],
document: {
actions: (previousActions, {schemaType}) => {
/*
* Please note that this will only alter the visibility of the button in the studio.
* Users with document publish permissions will be able to create schedules directly
* via the Scheduled Publishing API.
*/
if (schemaType.name !== 'movie') {
// Remove the schedule action from any documents that is not 'movie'.
return previousActions.filter((action) => action !== ScheduleAction)
}
return previousActions
},
},
})
This example assumes [you've customised your own document badges][document-badges] and would like to only show the Scheduled badge on movie documents only.
The Scheduled document badge displays whether the current document is scheduled and when it will be published if so. It is added to all document types by the plugin, so you should remove it from types that should NOT have it.
import {scheduledPublishing, ScheduledBadge} from '@sanity/scheduled-publishing'
export default defineConfig({
// ...
plugins: [scheduledPublishing()],
document: {
actions: (previousBadges, {schemaType}) => {
if (schemaType.name !== 'movie') {
// Remove the schedule badge from any documents that is not 'movie'.
return previousBadges.filter((badge) => badge !== ScheduledBadge)
}
return previousBadges
},
},
})
Schedules sit adjacent to your dataset and can be managed using the [Scheduling API][scheduling-api] (which this plugin does for you).
Schedules are a unique resource and are linked to, but do not exist within your Sanity project and dataset. It's important to understand the following behavior:
sanity dataset export will not include schedules and sanity dataset import does not support importing schedules.More information can be found on the [Scheduling API][scheduling-api] page.
</details> <details> <summary>Where is time zone data pulled from?</summary>