-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsanity.config.ts
108 lines (99 loc) · 3.48 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
/**
* This config is used to set up Sanity Studio that's mounted on the `/pages/studio/[[...index]].tsx` route
*/
import { visionTool } from '@sanity/vision'
import { apiVersion, dataset, previewSecretId, projectId } from 'lib/sanity.api'
import { pageStructure, singletonPlugin } from 'plugins/settings'
import { defineConfig } from 'sanity'
import { deskTool } from 'sanity/desk'
import { unsplashImageAsset } from 'sanity-plugin-asset-source-unsplash'
import Iframe, {
defineUrlResolver,
IframeOptions,
} from 'sanity-plugin-iframe-pane'
import { previewUrl } from 'sanity-plugin-iframe-pane/preview-url'
import page from 'schemas/documents/page'
import project from 'schemas/documents/project'
import duration from 'schemas/objects/duration'
import milestone from 'schemas/objects/milestone'
import timeline from 'schemas/objects/timeline'
import home from 'schemas/singletons/home'
import settings from 'schemas/singletons/settings'
const title =
process.env.NEXT_PUBLIC_SANITY_PROJECT_TITLE ||
'Next.js Personal Website with Sanity.io'
export const PREVIEWABLE_DOCUMENT_TYPES = [
home.name,
page.name,
project.name,
] satisfies string[]
export const PREVIEWABLE_DOCUMENT_TYPES_REQUIRING_SLUGS = [
page.name,
project.name,
] satisfies typeof PREVIEWABLE_DOCUMENT_TYPES
// Used to generate URLs for drafts and live previews
export const PREVIEW_BASE_URL = '/api/draft'
export const urlResolver = defineUrlResolver({
base: PREVIEW_BASE_URL,
requiresSlug: PREVIEWABLE_DOCUMENT_TYPES_REQUIRING_SLUGS,
})
export const iframeOptions = {
url: urlResolver,
urlSecretId: previewSecretId,
} satisfies IframeOptions
export default defineConfig({
basePath: '/studio',
projectId: projectId || '',
dataset: dataset || '',
title,
schema: {
// If you want more content types, you can add them to this array
types: [
// Singletons
home,
settings,
// Documents
duration,
page,
project,
// Objects
milestone,
timeline,
],
},
plugins: [
deskTool({
structure: pageStructure([home, settings]),
// `defaultDocumentNode` is responsible for adding a “Preview” tab to the document pane
// You can add any React component to `S.view.component` and it will be rendered in the pane
// and have access to content in the form in real-time.
// It's part of the Studio's “Structure Builder API” and is documented here:
// https://www.sanity.io/docs/structure-builder-reference
defaultDocumentNode: (S, { schemaType }) => {
if ((PREVIEWABLE_DOCUMENT_TYPES as string[]).includes(schemaType)) {
return S.document().views([
// Default form view
S.view.form(),
// Preview
S.view.component(Iframe).options(iframeOptions).title('Preview'),
])
}
return null
},
}),
// Configures the global "new document" button, and document actions, to suit the Settings document singleton
singletonPlugin([home.name, settings.name]),
// Add the "Open preview" action
previewUrl({
base: PREVIEW_BASE_URL,
requiresSlug: PREVIEWABLE_DOCUMENT_TYPES_REQUIRING_SLUGS,
urlSecretId: previewSecretId,
matchTypes: PREVIEWABLE_DOCUMENT_TYPES,
}),
// Add an image asset source for Unsplash
unsplashImageAsset(),
// Vision lets you query your content with GROQ in the studio
// https://www.sanity.io/docs/the-vision-plugin
visionTool({ defaultApiVersion: apiVersion }),
],
})