-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsanity.config.ts
95 lines (91 loc) · 3.34 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { obosAuthStore } from '@code-obos/sanity-auth';
import { codeInput } from '@sanity/code-input';
import { table } from '@sanity/table';
import { visionTool } from '@sanity/vision';
import { defineConfig } from 'sanity';
import { structureTool } from 'sanity/structure';
import { schemaTypes } from './studio/schema-types';
const dataset = 'grunnmuren';
export default defineConfig({
projectId: 'tq6w17ny',
dataset,
basePath: '/studio',
title: 'Grunnmuren - Sanity Studio',
auth: obosAuthStore({ dataset }),
plugins: [
structureTool({
structure: async (S, context) => {
const CATEGORIES = await context
.getClient({ apiVersion: '2025-03-21' })
.fetch(`(*[_type == "category"])`);
return S.list()
.title('Content')
.items([
S.listItem()
.id('menuAndCategories')
.title('Menu and categories')
.child(
S.list()
.title('Menu and categories')
.items([
// Our singleton type has a list item with a custom child
S.listItem()
.title('Menu')
.id('menu')
.child(
// Instead of rendering a list of documents, we render a single
// document, specifying the `documentId` manually to ensure
// that we're editing the single instance of the document
S.document()
.title('Menu')
.schemaType('menu')
.documentId('menu'),
),
S.divider(),
...CATEGORIES.map((category) => {
return S.listItem()
.title(category.title)
.id(category._id)
.child(
// Instead of rendering a list of documents, we render a single
// document, specifying the `documentId` manually to ensure
// that we're editing the single instance of the document
S.document()
.title(category.title)
.schemaType(category._type)
.documentId(category._id),
);
}),
]),
),
S.divider(),
S.documentTypeListItem('component').title('Components'),
S.documentTypeListItem('info').title('Info'),
]);
},
}),
visionTool(),
codeInput(),
table(),
],
schema: {
types: schemaTypes,
},
document: {
newDocumentOptions: (templateItems, { creationContext }) => {
// Define the singleton document types
const singletonTypes = new Set(['menu']);
// Check if the context is that of the top level "Create" button in the header
if (creationContext.type === 'global') {
const nonSingletonTemplateItems = [] as typeof templateItems;
for (const item of templateItems) {
if (!singletonTypes.has(item.templateId)) {
nonSingletonTemplateItems.push(item);
}
}
return nonSingletonTemplateItems;
}
return templateItems;
},
},
});