@kaliber/sanity-plugin-duplicate
v2.0.4
Published
Adds a (usable) duplicate to sanity
Downloads
130
Readme
Sanity plugin duplicate
Replaces the default duplicate function of Sanity and allows for the schema to determine how to handle duplication of specific fields.
Installation
> yarn add @kaliber/sanity-plugin-duplicateconfig/default.js
{
kaliber: [
compileWithBabel: [
/@kaliber\/sanity-plugin-duplicate/,
...
],
...
],
...
}admin/sanity.config.js
defineConfig({
...
plugins: [
preview({ reportError }),
...
],
})Signatures of reportError:
(e: Error) => voidAdditional setup
Customize duplication can be done by setting the Kaliber duplicate option.
import { clear } from '@kaliber/sanity-plugin-duplicate'
export const page = {
type: 'document',
name: 'page',
title: 'Page',
...
fields: [
{
title: 'My Field',
name: 'myField',
type: 'string',
...
options: {
kaliber: {
duplicate: clear,
...
},
...
}
}
]The duplicate option allows for the following values:
- A regular value, this value is used in the duplication
- The
clearsymbol, the field is cleared (removed) during duplication - A function, the function is called with the current value to generate a new value
Common example for things like titles:
options: {
kaliber: {
duplicate(previousValue) {
return `${previousValue} (copy)`
}
}
}Development
> yarn
> yarn linkproject/> yarn link @kaliber/sanity-plugin-duplicate
project/> yarn add @kaliber/sanity-plugin-duplicate@link:./node_modules/@kaliber/sanity-plugin-duplicatePublish
yarn publish
git push
git push --tags
Disclaimer
This library is intended for internal use, we provide no support, use at your own risk.
