-
Notifications
You must be signed in to change notification settings - Fork 1
/
sanity.config.ts
79 lines (76 loc) · 2.04 KB
/
sanity.config.ts
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
import { visionTool } from '@sanity/vision';
import { defineConfig } from 'sanity';
import { structureTool } from 'sanity/structure';
import { apiVersion, dataset, projectId } from './sanity/env';
import { schema } from './sanity/schema';
import { documentInternationalization } from '@sanity/document-internationalization';
import structure from './sanity/desk/structure';
import { translatedTypes, singletonTypes } from './sanity/desk/definition';
import { defaultLanguage, languageNames, languages } from './types/language';
const singletonActions = new Set(['publish', 'discardChanges', 'restore']);
export default defineConfig({
basePath: '/admin',
projectId,
dataset,
schema: {
...schema,
templates: (templates) =>
templates
.filter(({ schemaType }) => !singletonTypes.has(schemaType))
.filter(({ id }) => !translatedTypes.includes(id))
.filter(({ id }) => {
for (let i = 0; i < languages.length; i++) {
const language = languages[i];
for (let k = 0; k < translatedTypes.length; k++) {
const schemaType = translatedTypes[k];
if (
language !== defaultLanguage &&
id === `${schemaType}-${language}`
)
return false;
}
}
return true;
}),
},
plugins: [
structureTool({
structure,
defaultDocumentNode: (S) => S.document(),
}),
visionTool({ defaultApiVersion: apiVersion }),
documentInternationalization({
supportedLanguages: languages.map((language) => {
return {
id: language,
title: languageNames[language],
};
}),
schemaTypes: translatedTypes,
apiVersion,
}),
],
document: {
actions: (input, context) => {
return singletonTypes.has(context.schemaType)
? input.filter(({ action }) => action && singletonActions.has(action))
: input;
},
newDocumentOptions: (prev, { creationContext }) => {
const { type } = creationContext;
if (type === 'global') {
return [];
}
return prev;
},
},
redirects: () => {
return [
{
source: '/',
destination: '/se',
permanent: true,
},
];
},
});