Skip to content

Add (p)review document actions to Sanity

License

Notifications You must be signed in to change notification settings

kaliberjs/sanity-plugin-preview

Repository files navigation

Sanity plugin preview

Adds (p)review document actions to Sanity:

  • Preview - opens the preview URL in a new tab
  • Review - opens the published URL in a new tab

Installation

> yarn add @kaliber/sanity-plugin-preview

config/default.js

{
  kaliber: [
    compileWithBabel: [
      /@kaliber\/sanity-plugin-preview/,
      ...
    ],
    ...
  ],
  ...
}

admin/sanity.config.js

defineConfig({
    ...

    plugins: [
      preview({ resolvePublishedUrl, resolvePreviewUrl }),
      ...
    ],
})

Signatures of the required paramaters:

({ 
  document: SanityDocument, 
  schema: Schema, 
  getClient: (options: SourceClientOptions) => SanityClient 
}) => Promise<string | null>

Additional setup

It's possible to prevent 'preview' and 'view live' for documents that have required fields. A good example is the slug field, if that is missing we can not determine the route and thus can not preview.

Add the following to the schema in order to disable the buttons:

export const page = {
  type: 'document',
  name: 'page',
  title: 'Page',
  options: {
    kaliber: {
      requiredForPreview: ['slug'],
      ...
    },
  },
  ...

Development

> yarn
> yarn link
project/> yarn link @kaliber/sanity-plugin-preview

Publish

yarn publish
git push
git push --tags

Disclaimer

This library is intended for internal use, we provide no support, use at your own risk.

About

Add (p)review document actions to Sanity

Resources

License

Stars

Watchers

Forks

Packages

No packages published