-
Notifications
You must be signed in to change notification settings - Fork 5
/
sanity.config.ts
149 lines (135 loc) · 4.56 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
// TODO: fix the complains
// eslint-disable-next-line
// @ts-nocheck
import { codeInput } from '@sanity/code-input';
import { FilterIcon, TagIcon, UserIcon } from '@sanity/icons';
import { table } from '@sanity/table';
import { visionTool } from '@sanity/vision';
import { SanityDocument, defineConfig } from 'sanity';
import { Iframe } from 'sanity-plugin-iframe-pane';
import { media, mediaAssetSource } from 'sanity-plugin-media';
import { DefaultDocumentNodeResolver, structureTool } from 'sanity/structure';
import { schemaTypes } from './schemas';
const apiVersion = process.env.NEXT_PUBLIC_SANITY_API_VERSION!;
const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!;
const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET!;
interface ExtendedSanityDocument extends SanityDocument {
slug: {
current: string;
};
}
function getPreviewUrl(doc: ExtendedSanityDocument, categoryUrl: string = '') {
// TODO: setup preview like this https://www.sanity.io/docs/preview-url-secret
const host = process.env.NEXT_PUBLIC_DEFAULT_SITE_URL;
const url = new URL('/api/preview', host);
url.searchParams.append('secret', process.env.NEXT_PUBLIC_SANITY_PREVIEW_SECRET!);
url.searchParams.append(
'redirect_url',
new URL(`${categoryUrl}/${doc?.slug?.current ? `/${doc.slug.current}` : ''}`, host).toString(),
);
return url.toString();
}
export const defaultDocumentNode: DefaultDocumentNodeResolver = (S, { schemaType }) => {
switch (schemaType) {
case 'post':
return S.document().views([
S.view.form(),
S.view
.component(Iframe)
.options({
url: (doc: ExtendedSanityDocument) => getPreviewUrl(doc, '/blog'),
showDisplayUrl: false,
reload: {
button: true,
},
})
.title('Preview'),
]);
case 'customerStory':
return S.document().views([
S.view.form(),
S.view
.component(Iframe)
.options({
url: (doc: ExtendedSanityDocument) => getPreviewUrl(doc, '/customer-stories'),
showDisplayUrl: false,
reload: {
button: true,
},
})
.title('Preview'),
]);
default:
return S.document().views([S.view.form()]);
}
};
export default defineConfig({
basePath: '/studio',
name: 'default',
title: 'Taipy',
projectId,
dataset,
plugins: [
structureTool({
structure: (S) =>
S.list()
.title('Content')
.items([
...S.documentTypeListItems().filter((listItem) => listItem.getId() !== 'legal'),
S.divider(),
S.listItem()
.title('Filtered Posts')
.icon(FilterIcon)
.child(
S.list()
.title('Filter')
.items([
S.listItem()
.title('By Category')
.icon(TagIcon)
.child(
S.documentTypeList('category')
.title('Category')
.child((categoryId) =>
S.documentList()
.title('Post')
.filter('_type == "post" && $categoryId in categories[]._ref')
.params({ categoryId }),
),
),
S.listItem()
.title('By Author')
.icon(UserIcon)
.child(
S.documentTypeList('author')
.title('Author')
.child((authorId) =>
S.documentList()
.title('Post')
.filter('_type == "post" && $authorId == author._ref')
.params({ authorId }),
),
),
]),
),
S.divider(),
...S.documentTypeListItems().filter((listItem) => listItem.getId() === 'legal'),
]),
defaultDocumentNode,
}),
media(),
visionTool({ defaultApiVersion: apiVersion, defaultDataset: dataset }),
table(),
codeInput(),
],
form: {
// Don't use this plugin when selecting files only (but allow all other enabled asset sources)
file: {
assetSources: (previousAssetSources) =>
previousAssetSources.filter((assetSource) => assetSource !== mediaAssetSource),
},
},
schema: {
types: schemaTypes,
},
});