diff --git a/README.md b/README.md index e216f87..bd00d05 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,10 @@ export const createConfig({ defineField({ name: 'slug', type: 'slug' }) ], + // Optional + // Opt-out of static or parameterized initial value template generation + initialValueTemplates: false // defaults to true, also accepts "static", "parameterized" for just one or the other + // Optional // Define API Version for all queries // https://www.sanity.io/docs/api-versioning diff --git a/src/plugin.tsx b/src/plugin.tsx index 624bdff..79bdc01 100644 --- a/src/plugin.tsx +++ b/src/plugin.tsx @@ -21,6 +21,7 @@ export const documentInternationalization = definePlugin( languageField, bulkPublish, metadataFields, + initialValueTemplates, } = pluginConfig if (schemaTypes.length === 0) { @@ -124,32 +125,40 @@ export const documentInternationalization = definePlugin( return prev } - const parameterizedTemplates = schemaTypes.map((schemaType) => ({ - id: `${schemaType}-parameterized`, - title: `${ - schema?.get(schemaType)?.title ?? schemaType - }: with Language`, - schemaType, - parameters: [ - {name: `languageId`, title: `Language ID`, type: `string`}, - ], - value: ({languageId}: {languageId: string}) => ({ - [languageField]: languageId, - }), - })) - - const staticTemplates = schemaTypes.flatMap((schemaType) => { - return supportedLanguages.map((language) => ({ - id: `${schemaType}-${language.id}`, - title: `${language.title} ${ + if (initialValueTemplates === false) { + return prev + } + + if (initialValueTemplates !== 'static') { + const parameterizedTemplates = schemaTypes.map((schemaType) => ({ + id: `${schemaType}-parameterized`, + title: `${ schema?.get(schemaType)?.title ?? schemaType - }`, + }: with Language`, schemaType, - value: { - [languageField]: language.id, - }, + parameters: [ + {name: `languageId`, title: `Language ID`, type: `string`}, + ], + value: ({languageId}: {languageId: string}) => ({ + [languageField]: languageId, + }), })) - }) + } + + if (initialValueTemplates !== 'parameterized') { + const staticTemplates = schemaTypes.flatMap((schemaType) => { + return supportedLanguages.map((language) => ({ + id: `${schemaType}-${language.id}`, + title: `${language.title} ${ + schema?.get(schemaType)?.title ?? schemaType + }`, + schemaType, + value: { + [languageField]: language.id, + }, + })) + }) + } return [...prev, ...parameterizedTemplates, ...staticTemplates] },