sanity-plugin-seofields 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -171
- package/dist/index.d.mts +15 -189
- package/dist/index.d.ts +15 -189
- package/dist/index.js +230 -249
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +231 -250
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/SeoPreview.tsx +20 -19
- package/src/components/meta/MetaDescription.tsx +8 -17
- package/src/components/meta/MetaTitle.tsx +8 -17
- package/src/components/openGraph/OgDescription.tsx +6 -4
- package/src/components/openGraph/OgTitle.tsx +8 -6
- package/src/components/twitter/twitterDescription.tsx +9 -7
- package/src/components/twitter/twitterTitle.tsx +7 -5
- package/src/index.ts +3 -6
- package/src/plugin.ts +10 -9
- package/src/schemas/index.ts +10 -15
- package/src/schemas/types/index.ts +7 -5
- package/src/schemas/types/metaAttribute/index.ts +10 -14
- package/src/schemas/types/metaTag/index.ts +15 -14
- package/src/schemas/types/openGraph/index.ts +16 -5
- package/src/schemas/types/twitter/index.ts +16 -4
- package/src/types.ts +4 -65
- package/src/utils/fieldsUtils.ts +17 -96
- package/src/utils/seoUtils.ts +15 -15
- package/src/utils/utils.ts +2 -2
- package/src/types/index.ts +0 -241
- package/src/utils/generaeDynamicJsonLd.ts +0 -295
package/src/utils/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const isEmpty = (value:
|
|
1
|
+
export const isEmpty = (value: unknown): boolean => {
|
|
2
2
|
return (
|
|
3
3
|
value === null ||
|
|
4
4
|
value === undefined ||
|
|
@@ -6,4 +6,4 @@ export const isEmpty = (value: any): boolean => {
|
|
|
6
6
|
(Array.isArray(value) && value.length === 0) ||
|
|
7
7
|
(typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0)
|
|
8
8
|
)
|
|
9
|
-
}
|
|
9
|
+
}
|
package/src/types/index.ts
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
export type MetaAttribute = {
|
|
2
|
-
_type: 'metaAttribute'
|
|
3
|
-
key?: string
|
|
4
|
-
type?: 'string' | 'image'
|
|
5
|
-
value?: string
|
|
6
|
-
image?: {
|
|
7
|
-
asset?: {
|
|
8
|
-
_ref: string
|
|
9
|
-
_type: 'reference'
|
|
10
|
-
_weak?: boolean
|
|
11
|
-
[internalGroqTypeReferenceTo]?: 'sanity.imageAsset'
|
|
12
|
-
}
|
|
13
|
-
media?: unknown
|
|
14
|
-
hotspot?: SanityImageHotspot
|
|
15
|
-
crop?: SanityImageCrop
|
|
16
|
-
_type: 'image'
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type MetaTag = {
|
|
21
|
-
_type: 'metaTag'
|
|
22
|
-
metaAttributes?: Array<
|
|
23
|
-
{
|
|
24
|
-
_key: string
|
|
25
|
-
} & MetaAttribute
|
|
26
|
-
>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type SeoFields = {
|
|
30
|
-
_type: 'seoFields'
|
|
31
|
-
robots?: Robots
|
|
32
|
-
preview?: string
|
|
33
|
-
title?: string
|
|
34
|
-
description?: string
|
|
35
|
-
metaImage?: {
|
|
36
|
-
asset?: {
|
|
37
|
-
_ref: string
|
|
38
|
-
_type: 'reference'
|
|
39
|
-
_weak?: boolean
|
|
40
|
-
[internalGroqTypeReferenceTo]?: 'sanity.imageAsset'
|
|
41
|
-
}
|
|
42
|
-
media?: unknown
|
|
43
|
-
hotspot?: SanityImageHotspot
|
|
44
|
-
crop?: SanityImageCrop
|
|
45
|
-
_type: 'image'
|
|
46
|
-
}
|
|
47
|
-
metaAttributes?: Array<MetaAttribute>
|
|
48
|
-
keywords?: Array<string>
|
|
49
|
-
canonicalUrl?: string
|
|
50
|
-
openGraph?: OpenGraph
|
|
51
|
-
twitter?: Twitter
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type Twitter = {
|
|
55
|
-
_type: 'twitter'
|
|
56
|
-
card?: 'summary' | 'summary_large_image' | 'app' | 'player'
|
|
57
|
-
site?: string
|
|
58
|
-
creator?: string
|
|
59
|
-
title?: string
|
|
60
|
-
description?: string
|
|
61
|
-
image?: {
|
|
62
|
-
asset?: {
|
|
63
|
-
_ref: string
|
|
64
|
-
_type: 'reference'
|
|
65
|
-
_weak?: boolean
|
|
66
|
-
[internalGroqTypeReferenceTo]?: 'sanity.imageAsset'
|
|
67
|
-
}
|
|
68
|
-
media?: unknown
|
|
69
|
-
hotspot?: SanityImageHotspot
|
|
70
|
-
crop?: SanityImageCrop
|
|
71
|
-
alt?: string
|
|
72
|
-
_type: 'image'
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export type OpenGraph = {
|
|
77
|
-
_type: 'openGraph'
|
|
78
|
-
title?: string
|
|
79
|
-
url?: string
|
|
80
|
-
description?: string
|
|
81
|
-
siteName?: string
|
|
82
|
-
type?: 'website' | 'article' | 'profile' | 'book' | 'music' | 'video' | 'product'
|
|
83
|
-
imageType?: 'upload' | 'url'
|
|
84
|
-
image?: {
|
|
85
|
-
asset?: {
|
|
86
|
-
_ref: string
|
|
87
|
-
_type: 'reference'
|
|
88
|
-
_weak?: boolean
|
|
89
|
-
[internalGroqTypeReferenceTo]?: 'sanity.imageAsset'
|
|
90
|
-
}
|
|
91
|
-
media?: unknown
|
|
92
|
-
hotspot?: SanityImageHotspot
|
|
93
|
-
crop?: SanityImageCrop
|
|
94
|
-
_type: 'image'
|
|
95
|
-
}
|
|
96
|
-
imageUrl?: string
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export type Robots = {
|
|
100
|
-
_type: 'robots'
|
|
101
|
-
noIndex?: boolean
|
|
102
|
-
noFollow?: boolean
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export type SanityImagePaletteSwatch = {
|
|
106
|
-
_type: 'sanity.imagePaletteSwatch'
|
|
107
|
-
background?: string
|
|
108
|
-
foreground?: string
|
|
109
|
-
population?: number
|
|
110
|
-
title?: string
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export type SanityImagePalette = {
|
|
114
|
-
_type: 'sanity.imagePalette'
|
|
115
|
-
darkMuted?: SanityImagePaletteSwatch
|
|
116
|
-
lightVibrant?: SanityImagePaletteSwatch
|
|
117
|
-
darkVibrant?: SanityImagePaletteSwatch
|
|
118
|
-
vibrant?: SanityImagePaletteSwatch
|
|
119
|
-
dominant?: SanityImagePaletteSwatch
|
|
120
|
-
lightMuted?: SanityImagePaletteSwatch
|
|
121
|
-
muted?: SanityImagePaletteSwatch
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export type SanityImageDimensions = {
|
|
125
|
-
_type: 'sanity.imageDimensions'
|
|
126
|
-
height: number
|
|
127
|
-
width: number
|
|
128
|
-
aspectRatio: number
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export type SanityImageHotspot = {
|
|
132
|
-
_type: 'sanity.imageHotspot'
|
|
133
|
-
x: number
|
|
134
|
-
y: number
|
|
135
|
-
height: number
|
|
136
|
-
width: number
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export type SanityImageCrop = {
|
|
140
|
-
_type: 'sanity.imageCrop'
|
|
141
|
-
top: number
|
|
142
|
-
bottom: number
|
|
143
|
-
left: number
|
|
144
|
-
right: number
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export type SanityFileAsset = {
|
|
148
|
-
_id: string
|
|
149
|
-
_type: 'sanity.fileAsset'
|
|
150
|
-
_createdAt: string
|
|
151
|
-
_updatedAt: string
|
|
152
|
-
_rev: string
|
|
153
|
-
originalFilename?: string
|
|
154
|
-
label?: string
|
|
155
|
-
title?: string
|
|
156
|
-
description?: string
|
|
157
|
-
altText?: string
|
|
158
|
-
sha1hash?: string
|
|
159
|
-
extension?: string
|
|
160
|
-
mimeType?: string
|
|
161
|
-
size?: number
|
|
162
|
-
assetId?: string
|
|
163
|
-
uploadId?: string
|
|
164
|
-
path?: string
|
|
165
|
-
url?: string
|
|
166
|
-
source?: SanityAssetSourceData
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export type SanityImageAsset = {
|
|
170
|
-
_id: string
|
|
171
|
-
_type: 'sanity.imageAsset'
|
|
172
|
-
_createdAt: string
|
|
173
|
-
_updatedAt: string
|
|
174
|
-
_rev: string
|
|
175
|
-
originalFilename?: string
|
|
176
|
-
label?: string
|
|
177
|
-
title?: string
|
|
178
|
-
description?: string
|
|
179
|
-
altText?: string
|
|
180
|
-
sha1hash?: string
|
|
181
|
-
extension?: string
|
|
182
|
-
mimeType?: string
|
|
183
|
-
size?: number
|
|
184
|
-
assetId?: string
|
|
185
|
-
uploadId?: string
|
|
186
|
-
path?: string
|
|
187
|
-
url?: string
|
|
188
|
-
metadata?: SanityImageMetadata
|
|
189
|
-
source?: SanityAssetSourceData
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export type SanityImageMetadata = {
|
|
193
|
-
_type: 'sanity.imageMetadata'
|
|
194
|
-
location?: Geopoint
|
|
195
|
-
dimensions?: SanityImageDimensions
|
|
196
|
-
palette?: SanityImagePalette
|
|
197
|
-
lqip?: string
|
|
198
|
-
blurHash?: string
|
|
199
|
-
hasAlpha?: boolean
|
|
200
|
-
isOpaque?: boolean
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export type Geopoint = {
|
|
204
|
-
_type: 'geopoint'
|
|
205
|
-
lat?: number
|
|
206
|
-
lng?: number
|
|
207
|
-
alt?: number
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export type Slug = {
|
|
211
|
-
_type: 'slug'
|
|
212
|
-
current: string
|
|
213
|
-
source?: string
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export type SanityAssetSourceData = {
|
|
217
|
-
_type: 'sanity.assetSourceData'
|
|
218
|
-
name?: string
|
|
219
|
-
id?: string
|
|
220
|
-
url?: string
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export type AllSanitySchemaTypes =
|
|
224
|
-
| MetaAttribute
|
|
225
|
-
| MetaTag
|
|
226
|
-
| SeoFields
|
|
227
|
-
| Twitter
|
|
228
|
-
| OpenGraph
|
|
229
|
-
| Robots
|
|
230
|
-
| SanityImagePaletteSwatch
|
|
231
|
-
| SanityImagePalette
|
|
232
|
-
| SanityImageDimensions
|
|
233
|
-
| SanityImageHotspot
|
|
234
|
-
| SanityImageCrop
|
|
235
|
-
| SanityFileAsset
|
|
236
|
-
| SanityImageAsset
|
|
237
|
-
| SanityImageMetadata
|
|
238
|
-
| Geopoint
|
|
239
|
-
| Slug
|
|
240
|
-
| SanityAssetSourceData
|
|
241
|
-
export declare const internalGroqTypeReferenceTo: unique symbol
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import {SchemaTypeDefinition} from 'sanity'
|
|
2
|
-
// Import all schema definitions
|
|
3
|
-
import allSchemas from '../schemas/types'
|
|
4
|
-
|
|
5
|
-
interface JsonSchemaProperty {
|
|
6
|
-
type?: string | string[]
|
|
7
|
-
items?: JsonSchemaProperty
|
|
8
|
-
properties?: Record<string, JsonSchemaProperty>
|
|
9
|
-
required?: string[]
|
|
10
|
-
enum?: string[]
|
|
11
|
-
const?: any
|
|
12
|
-
default?: any
|
|
13
|
-
description?: string
|
|
14
|
-
maxLength?: number
|
|
15
|
-
minLength?: number
|
|
16
|
-
pattern?: string
|
|
17
|
-
format?: string
|
|
18
|
-
$ref?: string
|
|
19
|
-
allOf?: JsonSchemaProperty[]
|
|
20
|
-
additionalProperties?: boolean
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface JsonSchema {
|
|
24
|
-
$schema: string
|
|
25
|
-
title: string
|
|
26
|
-
description: string
|
|
27
|
-
type: string
|
|
28
|
-
definitions: Record<string, JsonSchemaProperty>
|
|
29
|
-
properties: Record<string, JsonSchemaProperty>
|
|
30
|
-
additionalProperties: boolean
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Converts Sanity field type to JSON Schema type
|
|
35
|
-
*/
|
|
36
|
-
function mapSanityTypeToJsonSchema(sanityType: string): string | string[] {
|
|
37
|
-
const typeMap: Record<string, string | string[]> = {
|
|
38
|
-
string: 'string',
|
|
39
|
-
text: 'string',
|
|
40
|
-
number: 'number',
|
|
41
|
-
boolean: 'boolean',
|
|
42
|
-
array: 'array',
|
|
43
|
-
object: 'object',
|
|
44
|
-
image: 'object',
|
|
45
|
-
url: 'string',
|
|
46
|
-
date: 'string',
|
|
47
|
-
datetime: 'string',
|
|
48
|
-
reference: 'object',
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return typeMap[sanityType] || 'string'
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Converts Sanity field definition to JSON Schema property
|
|
56
|
-
*/
|
|
57
|
-
function convertSanityFieldToJsonSchema(field: any): JsonSchemaProperty {
|
|
58
|
-
const jsonSchemaProperty: JsonSchemaProperty = {
|
|
59
|
-
type: mapSanityTypeToJsonSchema(field.type),
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Add description
|
|
63
|
-
if (field.description) {
|
|
64
|
-
jsonSchemaProperty.description = field.description
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Handle validation rules
|
|
68
|
-
if (field.validation) {
|
|
69
|
-
// This would need to be expanded based on your validation rules
|
|
70
|
-
// For now, we'll handle common cases
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Handle different field types
|
|
74
|
-
switch (field.type) {
|
|
75
|
-
case 'string':
|
|
76
|
-
if (field.options?.list) {
|
|
77
|
-
jsonSchemaProperty.enum = field.options.list.map((item: any) =>
|
|
78
|
-
typeof item === 'string' ? item : item.value,
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
if (field.validation) {
|
|
82
|
-
// Add length constraints if available
|
|
83
|
-
}
|
|
84
|
-
break
|
|
85
|
-
|
|
86
|
-
case 'text':
|
|
87
|
-
jsonSchemaProperty.type = 'string'
|
|
88
|
-
break
|
|
89
|
-
|
|
90
|
-
case 'url':
|
|
91
|
-
jsonSchemaProperty.type = 'string'
|
|
92
|
-
jsonSchemaProperty.format = 'uri'
|
|
93
|
-
break
|
|
94
|
-
|
|
95
|
-
case 'array':
|
|
96
|
-
jsonSchemaProperty.type = 'array'
|
|
97
|
-
if (field.of && field.of[0]) {
|
|
98
|
-
if (typeof field.of[0] === 'string') {
|
|
99
|
-
jsonSchemaProperty.items = {type: 'string'}
|
|
100
|
-
} else if (field.of[0].type) {
|
|
101
|
-
jsonSchemaProperty.items = convertSanityFieldToJsonSchema(field.of[0])
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
break
|
|
105
|
-
|
|
106
|
-
case 'object':
|
|
107
|
-
jsonSchemaProperty.type = 'object'
|
|
108
|
-
if (field.fields) {
|
|
109
|
-
jsonSchemaProperty.properties = {}
|
|
110
|
-
const required: string[] = []
|
|
111
|
-
|
|
112
|
-
field.fields.forEach((subField: any) => {
|
|
113
|
-
if (subField.name) {
|
|
114
|
-
jsonSchemaProperty.properties![subField.name] = convertSanityFieldToJsonSchema(subField)
|
|
115
|
-
if (subField.required) {
|
|
116
|
-
required.push(subField.name)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
if (required.length > 0) {
|
|
122
|
-
jsonSchemaProperty.required = required
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
jsonSchemaProperty.additionalProperties = false
|
|
126
|
-
break
|
|
127
|
-
|
|
128
|
-
case 'image':
|
|
129
|
-
jsonSchemaProperty.$ref = '#/definitions/SanityImage'
|
|
130
|
-
break
|
|
131
|
-
|
|
132
|
-
case 'reference':
|
|
133
|
-
jsonSchemaProperty.type = 'object'
|
|
134
|
-
jsonSchemaProperty.properties = {
|
|
135
|
-
_ref: {type: 'string'},
|
|
136
|
-
_type: {type: 'string', const: 'reference'},
|
|
137
|
-
}
|
|
138
|
-
jsonSchemaProperty.required = ['_ref', '_type']
|
|
139
|
-
break
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Handle initial values as defaults
|
|
143
|
-
if (field.initialValue !== undefined) {
|
|
144
|
-
jsonSchemaProperty.default = field.initialValue
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Handle hidden fields (not really applicable to JSON Schema but we can note it)
|
|
148
|
-
if (field.hidden) {
|
|
149
|
-
jsonSchemaProperty.description = (jsonSchemaProperty.description || '') + ' (Hidden field)'
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Handle read-only fields
|
|
153
|
-
if (field.readOnly) {
|
|
154
|
-
jsonSchemaProperty.description = (jsonSchemaProperty.description || '') + ' (Read-only)'
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return jsonSchemaProperty
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Converts a Sanity schema definition to JSON Schema definition
|
|
162
|
-
*/
|
|
163
|
-
function convertSanitySchemaToJsonSchema(schemaDefinition: any): JsonSchemaProperty {
|
|
164
|
-
const jsonSchemaDefinition: JsonSchemaProperty = {
|
|
165
|
-
type: 'object',
|
|
166
|
-
properties: {},
|
|
167
|
-
additionalProperties: false,
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Add _type property
|
|
171
|
-
if (schemaDefinition.name) {
|
|
172
|
-
jsonSchemaDefinition.properties!._type = {
|
|
173
|
-
type: 'string',
|
|
174
|
-
const: schemaDefinition.name,
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Add title and description
|
|
179
|
-
if (schemaDefinition.title) {
|
|
180
|
-
jsonSchemaDefinition.description = schemaDefinition.title
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Convert fields
|
|
184
|
-
if ('fields' in schemaDefinition && schemaDefinition.fields) {
|
|
185
|
-
const required: string[] = ['_type']
|
|
186
|
-
|
|
187
|
-
schemaDefinition.fields.forEach((field: any) => {
|
|
188
|
-
if (field.name) {
|
|
189
|
-
jsonSchemaDefinition.properties![field.name] = convertSanityFieldToJsonSchema(field)
|
|
190
|
-
if (field.required) {
|
|
191
|
-
required.push(field.name)
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
if (required.length > 1) {
|
|
197
|
-
// More than just _type
|
|
198
|
-
jsonSchemaDefinition.required = required
|
|
199
|
-
} else {
|
|
200
|
-
jsonSchemaDefinition.required = ['_type']
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return jsonSchemaDefinition
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Generates a complete JSON Schema from Sanity schema definitions
|
|
209
|
-
*/
|
|
210
|
-
function generateSchemaJson(): JsonSchema {
|
|
211
|
-
const schemas = allSchemas
|
|
212
|
-
|
|
213
|
-
const jsonSchema: JsonSchema = {
|
|
214
|
-
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
215
|
-
title: 'Sanity SEO Fields Plugin Schema',
|
|
216
|
-
description:
|
|
217
|
-
'Schema definitions for SEO fields including meta tags, Open Graph, and X (Formerly Twitter) Card settings',
|
|
218
|
-
type: 'object',
|
|
219
|
-
definitions: {},
|
|
220
|
-
properties: {},
|
|
221
|
-
additionalProperties: false,
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Add SanityImage definition
|
|
225
|
-
jsonSchema.definitions.SanityImage = {
|
|
226
|
-
type: 'object',
|
|
227
|
-
properties: {
|
|
228
|
-
_type: {type: 'string', const: 'image'},
|
|
229
|
-
asset: {
|
|
230
|
-
type: 'object',
|
|
231
|
-
properties: {
|
|
232
|
-
_ref: {type: 'string'},
|
|
233
|
-
_type: {type: 'string', const: 'reference'},
|
|
234
|
-
},
|
|
235
|
-
required: ['_ref', '_type'],
|
|
236
|
-
},
|
|
237
|
-
hotspot: {
|
|
238
|
-
type: 'object',
|
|
239
|
-
properties: {
|
|
240
|
-
x: {type: 'number'},
|
|
241
|
-
y: {type: 'number'},
|
|
242
|
-
height: {type: 'number'},
|
|
243
|
-
width: {type: 'number'},
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
crop: {
|
|
247
|
-
type: 'object',
|
|
248
|
-
properties: {
|
|
249
|
-
top: {type: 'number'},
|
|
250
|
-
bottom: {type: 'number'},
|
|
251
|
-
left: {type: 'number'},
|
|
252
|
-
right: {type: 'number'},
|
|
253
|
-
},
|
|
254
|
-
},
|
|
255
|
-
alt: {type: 'string'},
|
|
256
|
-
},
|
|
257
|
-
required: ['_type', 'asset'],
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// Convert each schema
|
|
261
|
-
schemas().forEach((schema) => {
|
|
262
|
-
if (schema.name) {
|
|
263
|
-
const jsonSchemaDefinition = convertSanitySchemaToJsonSchema(schema)
|
|
264
|
-
jsonSchema.definitions[schema.name] = jsonSchemaDefinition
|
|
265
|
-
jsonSchema.properties[schema.name] = {$ref: `#/definitions/${schema.name}`}
|
|
266
|
-
}
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
return jsonSchema
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Writes the generated schema to a file
|
|
274
|
-
*/
|
|
275
|
-
export function writeSchemaJson(outputPath: string = './schema.json'): void {
|
|
276
|
-
const schema = generateSchemaJson()
|
|
277
|
-
const fs = require('fs')
|
|
278
|
-
|
|
279
|
-
try {
|
|
280
|
-
fs.writeFileSync(outputPath, JSON.stringify(schema, null, 2))
|
|
281
|
-
console.log(`✅ Schema.json generated successfully at: ${outputPath}`)
|
|
282
|
-
} catch (error) {
|
|
283
|
-
console.error('❌ Error writing schema.json:', error)
|
|
284
|
-
throw error
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Returns the generated schema as an object
|
|
290
|
-
*/
|
|
291
|
-
export function getSchemaJson(): JsonSchema {
|
|
292
|
-
return generateSchemaJson()
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export default generateSchemaJson
|