-
Notifications
You must be signed in to change notification settings - Fork 3
/
sanity.config.ts
70 lines (60 loc) · 2.14 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
import { apiVersion, dataset, previewSecretId, projectId } from '@/lib/sanity.api';
import { pageStructure, singletonPlugin } from '@/plugins/settings';
import { visionTool } from '@sanity/vision';
import { defineConfig } from 'sanity';
import { unsplashImageAsset } from 'sanity-plugin-asset-source-unsplash';
import Iframe, { defineUrlResolver } from 'sanity-plugin-iframe-pane';
import { previewUrl } from 'sanity-plugin-iframe-pane/preview-url';
import { deskTool } from 'sanity/desk';
import page from '@/schemas/documents/page';
import settings from '@/schemas/singletons/settings';
import post from '@/schemas/documents/post';
import schema from '@/schemas/schema';
export const PREVIEWABLE_DOCUMENT_TYPES = [page.name, post.name];
type PreviewableDocumentType = (typeof PREVIEWABLE_DOCUMENT_TYPES)[number];
export const PREVIEWABLE_DOCUMENT_TYPES_REQUIRING_SLUGS = [page.name, post.name];
// Used to generate URLs for drafts and live previews
export const PREVIEW_BASE_URL = '/api/draft';
export const urlResolver = defineUrlResolver({
base: '/api/draft',
requiresSlug: PREVIEWABLE_DOCUMENT_TYPES_REQUIRING_SLUGS,
});
export const iframeOptions = {
url: urlResolver,
urlSecretId: previewSecretId,
};
const config = defineConfig({
basePath: '/admin',
projectId,
dataset,
title: 'Session Token',
schema: {
types: schema,
},
plugins: [
deskTool({
structure: pageStructure([settings]),
defaultDocumentNode: (S, { schemaType }) => {
if (PREVIEWABLE_DOCUMENT_TYPES.includes(schemaType as PreviewableDocumentType)) {
return S.document().views([
// Default form view
S.view.form(),
// Preview
S.view.component(Iframe).options(iframeOptions).title('Preview'),
]);
}
return null;
},
}),
singletonPlugin([settings.name]),
previewUrl({
base: PREVIEW_BASE_URL,
requiresSlug: PREVIEWABLE_DOCUMENT_TYPES_REQUIRING_SLUGS,
urlSecretId: previewSecretId,
matchTypes: PREVIEWABLE_DOCUMENT_TYPES,
}),
unsplashImageAsset(),
visionTool({ defaultApiVersion: apiVersion }),
],
});
export default config;