🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@kaliber/sanity-plugin-preview

Package Overview
Dependencies
Maintainers
10
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kaliber/sanity-plugin-preview

Adds a (p)review document action to Sanity

latest
Source
npmnpm
Version
2.0.2
Version published
Maintainers
10
Created
Source

Sanity plugin preview

Adds (p)review document actions to Sanity.

Installation

> cd admin
> yarn add @kaliber/sanity-plugin-preview

admin/sanity.json

{
  "plugins": [
    "@kaliber/sanity-plugin-preview",
    ...
  ],
  ...
}

Prerequisites

This plugin expects your project to:

  • Handle the /${documentPath}?preview=${previewSecret} route at the front office using @kaliber/sanity-preview.
  • Implement the part:@kaliber/resolve-production-url part at the back office.
  • Add the document actions to the default document actions, by implementing the part:@sanity/base/document-actions/resolver part.

Check kaliber-sanity-template for a concrete example.

Implementing the part:@kaliber/resolve-production-url part

Create a file called resolveProductionUrl.js in your sanity folder. It should export an async function resolveProductionUrl, that returns the url to the given document tacking on the queryString given:

import qs from 'query-string' 

export async function resolveProductionUrl(document, { queryString = undefined } = {}) {
  // ... fetch path based on document

  return [
    path,
    queryString && qs.stringify(queryString)
  ].filter(Boolean).join('?')
}

Next, add it to the parts array in your sanity.json file:

{
  "implements": "part:@kaliber/resolve-production-url",
  "path": "./resolveProductionUrl.js"
}

Adding the custom document actions

To add the actual document actions, you have to add them to the default document actions. To do this, in your sanity folder create a file called resolveDocumentActions.js and add the following:

import defaultResolve from 'part:@sanity/base/document-actions'
import { DocumentActionProductionPreview, DocumentActionProductionReview } from '@kaliber/sanity-plugin-preview'

export default function resolveDocumentActions(props) {
  return [...defaultResolve(props), DocumentActionProductionPreview, DocumentActionProductionReview]
}

Then add the part:@sanity/base/document-actions/resolver part to the parts array in sanity.json:

{
  "implements": "part:@sanity/base/document-actions/resolver",
  "path": "./resolveDocumentActions.js"
}

Development

> yarn
> yarn link
> yarn watch
project/admin/> 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.

Keywords

sanity

FAQs

Package last updated on 14 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts