-
Notifications
You must be signed in to change notification settings - Fork 5
/
sanity.config.ts
96 lines (81 loc) · 3.01 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
96
'use client'
/**
* This configuration is used to for the Sanity Studio that’s mounted on the `/app/admin/[[...tool]]/page.tsx` route
*/
import {visionTool} from '@sanity/vision'
import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
// Go to https://www.sanity.io/docs/api-versioning to learn how API versioning works
import {apiVersion, dataset, projectId} from './sanity/env'
import {schema} from './sanity/schema'
// export default defineConfig({
// basePath: '/admin',
// projectId,
// dataset,
// // Add and edit the content schema in the './sanity/schema' folder
// schema,
// plugins: [
// structureTool(),
// // Vision is a tool that lets you query your content with GROQ in the studio
// // https://www.sanity.io/docs/the-vision-plugin
// visionTool({defaultApiVersion: apiVersion}),
// ],
// })
// Define the actions that should be available for singleton documents
const singletonActions = new Set(["publish", "discardChanges", "restore"])
const multiInstanceSchemas=["gallery","events","testimonial","contact"]
const multiInstanceTypes = schema.types.filter(type=>multiInstanceSchemas.includes(type.name))
const singletonTypes = schema.types.filter(type=>!multiInstanceSchemas.includes(type.name))
export default defineConfig({
name: "default",
title: "Krishaveni AshrayaDhama",
basePath: '/admin',
projectId,
dataset,
plugins: [
structureTool({
structure: (S) =>
S.list()
.title("Content")
.items(
[
...schema.
types
.filter(type=>(!multiInstanceSchemas.includes(type.name))&&type.type!=="object")
.map(type=>{
// Our singleton type has a list item with a custom child
return S.listItem()
.title(type.title||type.name)
.id(type.name)
.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()
.schemaType(type.name)
.documentId(type.name)
)
}),
...multiInstanceTypes.map(type=>(
S.documentTypeListItem(type.name).title(type.title||type.name)
))
]),
}),
visionTool(),
],
schema: {
types: schema.types,
// Filter out singleton types from the global “New document” menu options
templates: (templates) =>
templates.filter(({ schemaType }) => multiInstanceSchemas.includes(schemaType)),
},
document: {
// For singleton types, filter out actions that are not explicitly included
// in the `singletonActions` list defined above
actions: (input, context) =>
singletonTypes.filter(type=>context.schemaType===type.name).length
? input.filter(({ action }) => action && singletonActions.has(action))
:
input,
},
})