-
Notifications
You must be signed in to change notification settings - Fork 1
/
sanity.config.js
92 lines (90 loc) · 2.95 KB
/
sanity.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { documentInternationalization } from '@sanity/document-internationalization';
import { defineConfig } from 'sanity';
import { structureTool } from 'sanity/structure';
import { assist } from '@sanity/assist';
import deskStructure from './deskStructure';
import schemas, { documentsSchemas } from './schemas/schema';
import { uniqueDocuments } from './uniqueDocuments';
import { languages } from './languages';
const config = {
projectId: process.env.SANITY_STUDIO_PROJECT_ID,
plugins: [
structureTool({
structure: deskStructure,
}),
documentInternationalization({
supportedLanguages: languages,
schemaTypes: documentsSchemas.map(schema => schema.name),
}),
assist({
translate: {
document: {
languageField: 'language',
},
},
}),
],
schema: {
types: schemas,
},
document: {
newDocumentOptions: (prev, { creationContext }) => {
console.log( prev)
return (
prev
.filter(templateItem =>
// Removes certain document types from the global “create new” menu in the top left navigation bar
creationContext.type === 'global'
? !uniqueDocuments.includes(templateItem.templateId.replace(/-es$|-en$/, ''))
: true,
)
.filter(templateItem =>
// Only allows to create either English or Spanish documents
templateItem.templateId.endsWith('-en') ||
templateItem.templateId.endsWith('-es'),
)
// eg Update title from "English Example Doc" to "Example Doc (EN)"
.map(templateItem => ({
...templateItem,
title: templateItem.title.replace(
/^(English|Spanish) (.+)/,
(_, language, rest) => {
const languageCode = language === 'English' ? 'EN' : 'ES';
return `${rest} (${languageCode})`;
},
),
}))
);
},
// Disable unpublish, delete, and duplicate actions in the documents actions menu
actions: (prev, { schemaType }) => {
if (uniqueDocuments.includes(schemaType)) {
return prev.filter(
({ action }) => !['unpublish', 'delete', 'duplicate'].includes(action),
);
}
return prev;
},
},
};
export default defineConfig([
{
title: 'regen-sanity',
// The default dataset will be set to production in the deployed studio (see .env.production)
// but it will usually be staging in local dev for easier access.
dataset: process.env.SANITY_STUDIO_DATASET,
name: 'default-workspace',
basePath: '/default',
...config,
},
{
title: 'regen-sanity-staging',
// The secondary workspace always uses the staging dataset.
// This is primarily useful for content editors to edit content on staging
// from the deployed studio when needed.
dataset: 'staging',
name: 'staging-workspace',
basePath: '/staging',
...config,
},
]);