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
> 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>
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'],
...
},
},
...
> yarn
> yarn link
project/> yarn link @kaliber/sanity-plugin-preview
yarn publish
git push
git push --tags
This library is intended for internal use, we provide no support, use at your own risk.