-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsanity.config.ts
More file actions
122 lines (117 loc) · 3.71 KB
/
Copy pathsanity.config.ts
File metadata and controls
122 lines (117 loc) · 3.71 KB
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
'use client';
/**
* This config is used to configure your Sanity Studio.
* Learn more: https://www.sanity.io/docs/configuration
*/
import { assist } from '@sanity/assist';
import { visionTool } from '@sanity/vision';
import { defineConfig } from 'sanity';
import {
type DocumentLocation,
defineDocuments,
defineLocations,
presentationTool,
} from 'sanity/presentation';
import { structureTool } from 'sanity/structure';
import { clientEnv } from '@/env/clientEnv';
import { schemaTypes } from './src/studio/schema';
import { structure } from './src/studio/structure';
// Define the home location for the presentation tool
const homeLocation = {
title: 'Home',
href: '/',
} satisfies DocumentLocation;
// resolveHref() is a convenience function that resolves the URL
// path for different document types and used in the presentation tool.
function resolveHref(documentType?: string, slug?: string): string | undefined {
switch (documentType) {
case 'post':
return slug ? `/blog/${slug}` : undefined;
case 'page':
return slug ? `/${slug}` : undefined;
default:
console.warn('Invalid document type:', documentType);
return undefined;
}
}
// Main Sanity configuration
export default defineConfig({
basePath: '/studio',
name: 'default',
title: 'Ignite for Sanity',
projectId: clientEnv.NEXT_PUBLIC_SANITY_PROJECT_ID,
dataset: clientEnv.NEXT_PUBLIC_SANITY_DATASET,
plugins: [
// Presentation tool configuration for Visual Editing
presentationTool({
previewUrl: {
// origin: SANITY_STUDIO_PREVIEW_URL,
previewMode: {
enable: '/api/draft-mode/enable',
},
},
resolve: {
// The Main Document Resolver API provides a method of resolving a main document from a given route or route pattern. https://www.sanity.io/docs/presentation-resolver-api#57720a5678d9
mainDocuments: defineDocuments([
{
route: '/:slug',
filter: `_type == "page" && slug.current == $slug || _id == $slug`,
},
{
route: '/blog/:slug',
filter: `_type == "post" && slug.current == $slug || _id == $slug`,
},
]),
// Locations Resolver API allows you to define where data is being used in your application. https://www.sanity.io/docs/presentation-resolver-api#8d8bca7bfcd7
locations: {
settings: defineLocations({
locations: [homeLocation],
message: 'This document is used on all pages',
tone: 'positive',
}),
page: defineLocations({
select: {
name: 'name',
slug: 'slug.current',
},
resolve: (doc) => ({
locations: [
{
title: doc?.name || 'Untitled',
href: resolveHref('page', doc?.slug)!,
},
],
}),
}),
post: defineLocations({
select: {
title: 'title',
slug: 'slug.current',
},
resolve: (doc) => ({
locations: [
{
title: doc?.title || 'Untitled',
href: resolveHref('post', doc?.slug)!,
},
{
title: 'Home',
href: '/',
} satisfies DocumentLocation,
].filter(Boolean) as DocumentLocation[],
}),
}),
},
},
}),
structureTool({
structure, // Custom studio structure configuration, imported from ./src/structure.ts
}),
// Additional plugins for enhanced functionality
assist(),
visionTool(),
],
schema: {
types: schemaTypes,
},
});