Replaces the default duplicate function of Sanity and allows for the schema to determine how to handle duplication of specific fields.
> yarn add @kaliber/sanity-plugin-duplicate
config/default.js
{
kaliber: [
compileWithBabel: [
/@kaliber\/sanity-plugin-duplicate/,
...
],
...
],
...
}
admin/sanity.config.js
defineConfig({
...
plugins: [
preview({ reportError }),
...
],
})
Signatures of reportError
:
(e: Error) => void
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
clear
symbol, 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)`
}
}
}
> yarn
> yarn link
project/> yarn link @kaliber/sanity-plugin-duplicate
project/> yarn add @kaliber/sanity-plugin-duplicate@link:./node_modules/@kaliber/sanity-plugin-duplicate
yarn publish
git push
git push --tags
This library is intended for internal use, we provide no support, use at your own risk.