This is a fork of the now vendored scheduled publishing plugin. The plugin itself is deployed as a private npm package
Schedule your content for future publication and organise upcoming releases – no custom tasks or serverless functions required!
This plugin uses Sanity's Scheduling API which is available to customers on Growth or higher plans.
- Create and edit schedules for the document you're working on
- See current schedule status and potential validation issues
- Filter all schedules by status or use the calendar to browse by date
- Edit, delete, and immediately publish schedules
- Automatically validate upcoming schedules, and identify issues before they're published
- Easily identify who created a schedule
- Change the time zone you want to preview schedules in by clicking the 🌎 Time Zone button when visible. Great when you need to co-ordinate with a global team or want to time publication to specific regions.
- Easily select time zones by city, time zone abbreviation or name search.
- Selected time zones are automatically stored in your local storage for future use.
npm install --save @sanity/scheduled-publishing
or
yarn add @sanity/scheduled-publishing
Add it as a plugin in sanity.config.ts (or .js):
import {scheduledPublishing} from '@sanity/scheduled-publishing'
export default defineConfig({
// ...
plugins: [scheduledPublishing()],
})
This will automatically:
- Add a Schedule document action to all document types
- Display a Scheduled document badge to all document types
- Add the dedicated Schedules tool in your navigation bar
Please see Custom setup for more fine grained control on limiting schedule buttons to specific document types and working with existing custom document actions or badges.
This plugin also exports both the Schedule document action and Scheduled badge which you can import and compose as you see fit.
This example assumes you've customised your own 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 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
},
},
})
What's the relationship between Schedules and my dataset?
Schedules sit adjacent to your dataset and can be managed using the 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:
- As schedules are not contained within a project’s dataset, you cannot query them via GROQ or GraphQL.
- Deleting a dataset will immediately delete all schedules.
- Deleting a project will immediately delete all schedules.
sanity dataset export
will not include schedules andsanity dataset import
does not support importing schedules.- Server-side copying of datasets does not include schedules.
- When a project is disabled or blocked, all scheduled publishes will invariably fail as mutations will not be allowed on the dataset.
More information can be found on the Scheduling API page.
Where is time zone data pulled from?
-
Time zones and their corresponding cities, regions and daylight savings offsets are directly sourced from the @vvo/dztb library, which is automatically updated with data from geonames.org.
-
Latest time zone + region data from @vvo/dztb is pulled in when first installing this plugin.
-
In the event you need to bring in upstream time zone and region data, run:
# Yarn yarn upgrade @sanity/scheduled-publishing # NPM npm update @vvo/tzdb --legacy-peer-deps
Will scheduled documents with validation errors publish?
- Yes. Documents scheduled to publish in future will do so, even if they contain validation errors. This also applies to scheduled documents that you manually opt to publish immediately via the tool.
The Studio V3 version differs from the v2 versions in a few ways:
- Actions and badges now auto-compose with other document actions by default. This is the opposite of how the v2 version behaves: It is no longer necessary to compose actions and badges manually when there are other plugins that add those to studio.
- This means that you now have to remove the Schedule Action from types that should not have it, as opposed to add it for those that should like in v2.
This repository is published under the MIT license.
This plugin uses @sanity/plugin-kit with default configuration for build & watch scripts.
See Testing a plugin in Sanity Studio on how to run this plugin with hotreload in the studio.
MIT-licensed. See LICENSE.
This plugin uses @sanity/plugin-kit with default configuration for build & watch scripts.
See Testing a plugin in Sanity Studio on how to run this plugin with hotreload in the studio.
Run "CI & Release" workflow. Make sure to select the main branch and check "Release new version".
Semantic release will only release on configured branches, so it is safe to run release on any branch.