Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

Scheduled Publishing

Official(made by Sanity team)

Schedule your content for future publication and organize upcoming releases – no custom tasks or serverless functions required!

Scheduled Publishing plugin for Sanity.io

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 Team or higher plans. Please visit our Scheduled Publishing blog post for more information.

Scheduled Publishing tool view

Scheduled Publishing document view

Features

Create and edit schedules directly from the document editor

  • Create and edit schedules for the document you're working on
  • See current schedule status and potential validation issues

View all your schedules with our dedicated tool

  • 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

View schedule dates in any remote time zone

  • 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.

Getting started

In your Sanity studio folder:

sanity install @sanity/scheduled-publishing

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.

Custom setup

This plugin also exports both the Schedule document action and Scheduled badge which you can import and compose as you see fit.

Manually adding the Schedule document action

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.

import {ScheduleAction} from '@sanity/scheduled-publishing'
import defaultResolve from 'part:@sanity/base/document-actions'

/*
 * 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.
 */

export default function resolveDocumentActions(props) {
  // Default document actions
  const defaultActions = defaultResolve(props)

  // Show the schedule button on `movie` documents only
  if (props.type === 'movie') {
    // Add our schedule action AFTER the first action (publish, by default)
    // to ensure it sits at the top of our document context menu.
    return [...defaultActions.slice(0, 1), ScheduleAction, ...defaultActions.slice(1)]
  }

  // Finally, return default actions for all other document types
  return defaultActions
}

Manually adding the Scheduled document badge

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.

import {ScheduledBadge} from '@sanity/scheduled-publishing'
import defaultResolve from 'part:@sanity/base/document-badges'

export default function resolveDocumentBadges(props) {
  // Default document badges
  const defaultBadges = defaultResolve(props)

  // Show the scheduled badge on `movie` documents only
  if (props.type === 'movie') {
    // Add our scheduled badge after any defaults
    return [...defaultBadges, ScheduledBadge]
  }

  // Return default badges for all other document types
  return defaultBadges
}

FAQ

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 and sanity 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.

License

This repository is published under the MIT license.

Install command

sanity install @sanity/scheduled-publishing