forked from nuotsu/sanitypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaultDocumentNode.ts
48 lines (41 loc) · 1.17 KB
/
defaultDocumentNode.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
import { isDev, type SanityDocument } from 'sanity'
import { Iframe } from 'sanity-plugin-iframe-pane'
import { VscEdit, VscEye } from 'react-icons/vsc'
import type { DefaultDocumentNodeResolver } from 'sanity/structure'
const previewUrl = 'https://next-sanity-template-demo.vercel.app'
const defaultDocumentNode: DefaultDocumentNodeResolver = (
S,
{ schemaType },
) => {
const editorView = S.view.form().icon(VscEdit)
switch (schemaType) {
case 'page':
case 'blog.post':
return S.document().views([
editorView,
S.view
.component(Iframe)
.title('Preview')
.icon(VscEye)
.options({
url: (
doc: SanityDocument & {
metadata?: { slug?: { current: string } }
},
) => {
const base = isDev ? 'http://localhost:3000' : previewUrl
const slug = doc?.metadata?.slug?.current
const path = slug === 'index' ? '' : slug
const directory = schemaType === 'blog.post' ? 'blog' : null
return [base, directory, path].filter(Boolean).join('/')
},
reload: {
button: true,
},
}),
])
default:
return S.document().views([editorView])
}
}
export default defaultDocumentNode