-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
sanity.config.ts
194 lines (188 loc) · 6.25 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
"use client";
/**
* This config is used to set up Sanity Studio that's mounted on the `app/(sanity)/studio/[[...tool]]/page.tsx` route
*/
import { visionTool } from "@sanity/vision";
import { PluginOptions, defineConfig } from "sanity";
import { cloudinarySchemaPlugin } from "sanity-plugin-cloudinary";
import { tags } from "sanity-plugin-tags";
import { codeInput } from "@sanity/code-input";
import { iconPicker } from "sanity-plugin-icon-picker";
import { podcastRss } from "@codingcatdev/sanity-plugin-podcast-rss";
// TODO: Review for possible plugins
// import {draftReviewPluginV3} from 'sanity-plugin-draft-review-v3'
// https://github.com/jamesreaco/inbox-tool-sanity
// https://www.sanity.io/plugins/vercel-deploy
// https://github.com/sanity-io/document-internationalization
import {
presentationTool,
defineDocuments,
defineLocations,
type DocumentLocation,
} from "sanity/presentation";
import { DocumentTypeListBuilder, StructureResolver, structureTool } from "sanity/structure";
import { apiVersion, dataset, projectId, studioUrl } from "@/sanity/lib/api";
import { pageStructure, singletonPlugin } from "@/sanity/plugins/settings";
import { assistWithPresets } from "@/sanity/plugins/assist";
import author from "@/sanity/schemas/documents/author";
import course from "@/sanity/schemas/documents/course";
import lesson from "@/sanity/schemas/documents/lesson";
import guest from "@/sanity/schemas/documents/guest";
import page from "@/sanity/schemas/documents/page";
import podcast from "@/sanity/schemas/documents/podcast";
import podcastType from "@/sanity/schemas/documents/podcastType";
import post from "@/sanity/schemas/documents/post";
import settings from "@/sanity/schemas/singletons/settings";
import sponsor from "@/sanity/schemas/documents/sponsor";
import { resolveHref } from "@/sanity/lib/utils";
const homeLocation = {
title: "Home",
href: "/",
} satisfies DocumentLocation;
export const podcastStructure = (
structure: StructureResolver
): StructureResolver => {
return (S) => {
return S.list()
.title("Content")
.items([
S.listItem()
.title('Podcasts')
.child(
S.list()
.title("Filters")
.items([
S.listItem()
.title('By Type')
.child(
S.documentTypeList('podcastType')
.title('Podcast by Type')
.child((podcastTypeId) =>
S.documentList()
.title('Podcasts')
.filter('_type == "podcast" && $podcastTypeId == podcastType._ref')
.params({ podcastTypeId })
)
),
S.listItem()
.title('Missing Hashnode')
.child(() =>
S.documentList()
.title('Podcasts')
.filter('_type == "podcast" && hashnode == null')
),
S.listItem()
.title('Missing Dev.to')
.child(() =>
S.documentList()
.title('Podcasts')
.filter('_type == "podcast" && devto == null')
),
S.listItem()
.title('Missing Season')
.child(() =>
S.documentList()
.title('Podcasts')
.filter('_type == "podcast" && season == null')
),
S.listItem()
.title('Missing Episode')
.child(() =>
S.documentList()
.title('Podcasts')
.filter('_type == "podcast" && episode == null')
),
S.listItem()
.title('Missing YouTube')
.child(() =>
S.documentList()
.title('Podcasts')
.filter('_type == "podcast" && youtube == null')
),
])
),
...S.documentTypeListItems()
// .filter(
// (listItem) => !['podcast'].includes(`${listItem.getId()}`)
// ),
]);
};
};
export default defineConfig({
basePath: studioUrl,
projectId,
dataset,
schema: {
types: [
// Singletons
settings,
// Documents
author,
course,
lesson,
guest,
page,
podcast,
podcastType,
post,
sponsor,
],
},
plugins: [
presentationTool({
resolve: {
mainDocuments: defineDocuments([
{
route: "/post/:slug",
filter: `_type == "post" && slug.current == $slug`,
},
]),
locations: {
settings: defineLocations({
locations: [homeLocation],
message: "This document is used on all pages",
tone: "caution",
}),
post: defineLocations({
select: {
title: "title",
slug: "slug.current",
},
resolve: (doc) => ({
locations: [
{
title: doc?.title || "Untitled",
href: resolveHref("post", doc?.slug)!,
},
homeLocation,
],
}),
}),
},
},
previewUrl: { previewMode: { enable: "/api/draft" } },
}),
structureTool({ structure: podcastStructure(pageStructure([settings])) }),
// Configures the global "new document" button, and document actions, to suit the Settings document singleton
singletonPlugin([settings.name]),
// Sets up AI Assist with preset prompts
// https://www.sanity.io/docs/ai-assist
assistWithPresets(),
cloudinarySchemaPlugin(),
tags(),
codeInput(),
iconPicker(),
podcastRss({
podcasts: [
{
title: "CodingCat.dev",
url: "https://anchor.fm/s/115b203c/podcast/rss",
},
],
}),
// Vision lets you query your content with GROQ in the studio
// https://www.sanity.io/docs/the-vision-plugin
process.env.NODE_ENV === "development" &&
visionTool({ defaultApiVersion: apiVersion }),
].filter(Boolean) as PluginOptions[],
});