-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsanity.config.tsx
124 lines (115 loc) · 3.86 KB
/
sanity.config.tsx
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { languages, LanguageType } from "./languages";
import { Logo } from "./studio/components/Logo";
import { createPublishAction } from "./studio/components/PublishAction";
import { productionURLPane } from "./studio/components/productionURLPane";
import { schemaTypes } from "./studio/schemas";
import { structure, defaultDocumentNode } from "./studio/structure";
import {
LINKABLE_SCHEMAS,
SANITY_API_VERSION,
TRANSLATABLE_SCHEMAS,
} from "./types.sanity";
import { languageFilter } from "@sanity/language-filter";
import { visionTool } from "@sanity/vision";
import { defineConfig, Template } from "sanity";
import { media } from "sanity-plugin-media";
import { muxInput } from "sanity-plugin-mux-input";
import { deskTool } from "sanity/desk";
const env = import.meta.env;
export default defineConfig({
projectId: env.SANITY_STUDIO_API_PROJECT_ID,
dataset: env.SANITY_STUDIO_API_DATASET,
title: "Sanity Studio",
plugins: [
deskTool({
structure,
defaultDocumentNode,
}),
languageFilter({
supportedLanguages: languages,
documentTypes: Object.keys(TRANSLATABLE_SCHEMAS),
filterField: (enclosingType, field, selectedLanguageIds) => {
return !(
languages.map(({ id }) => id).includes(field.name as LanguageType) &&
!selectedLanguageIds.includes(field.name)
);
},
}),
media(),
visionTool({
defaultApiVersion: SANITY_API_VERSION,
}),
muxInput(),
productionURLPane,
],
document: {
actions: (prev, context) => {
const schema = Object.entries(context.schema._registry)
.find(([key, value]) => key === context.schemaType)?.[1]
.get();
if (schema.options?.singleton) {
return [
...prev
.filter(
({ action }) =>
action == "publish" ||
action == "unpublish" ||
action == "delete",
)
.map((originalAction) =>
originalAction.action === "publish"
? createPublishAction(originalAction)
: originalAction,
),
];
}
return prev.map((originalAction) =>
originalAction.action === "publish"
? createPublishAction(originalAction)
: originalAction,
);
},
newDocumentOptions: (prev, context) => {
prev = prev.filter((option: any) => {
if (option.templateId.startsWith("config.")) return false;
if (option.templateId.startsWith("media.")) return false;
if (option.templateId.startsWith("card.")) return false;
if (option.templateId.startsWith("password.")) return false;
if (option.templateId === "footer") return false;
if (option.templateId === "navigation") return false;
if (option.templateId === "page.home") return false;
if (option.templateId === "page.notfound") return false;
if (option.templateId === "page.sitemap") return false;
const schema = context?.schema?._original?.types.find(
({ name }: { name: string }) => name === option.templateId,
);
if ((schema?.options as any)?.singleton) return false;
return true;
});
return prev;
},
},
schema: {
types: schemaTypes,
templates: Object.keys(LINKABLE_SCHEMAS)
.map((schemaType) => {
const schema = schemaTypes.find(({ name }) => name === schemaType);
if (schema.options?.singleton) return null;
return {
id: `${schemaType}-with-language`,
title: schema.title,
parameters: [{ name: "language", type: "string" }],
schemaType: schemaType,
value: (params: { language: LanguageType }) => ({
language: params?.language,
}),
};
})
.filter(Boolean) as Template<any, any>[],
},
studio: {
components: {
logo: Logo,
},
},
});