sanity-plugin-seofields 1.0.1 → 1.0.2
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 +81 -6
- package/dist/index.d.mts +31 -19
- package/dist/index.d.ts +31 -19
- package/dist/index.js +252 -201
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +254 -203
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/meta/MetaDescription.tsx +12 -11
- package/src/components/meta/MetaTitle.tsx +12 -11
- package/src/components/openGraph/OgDescription.tsx +5 -4
- package/src/components/openGraph/OgTitle.tsx +3 -2
- package/src/components/twitter/twitterDescription.tsx +3 -2
- package/src/components/twitter/twitterTitle.tsx +3 -2
- package/src/index.ts +5 -2
- package/src/plugin.ts +18 -18
- package/src/schemas/index.ts +100 -88
- package/src/schemas/types/index.ts +12 -1
- package/src/utils/fieldsUtils.ts +137 -0
- package/src/utils/generaeDynamicJsonLd.ts +1 -1
- package/src/utils/seoUtils.ts +133 -96
package/src/schemas/index.ts
CHANGED
|
@@ -2,92 +2,104 @@ import {defineField, defineType} from 'sanity'
|
|
|
2
2
|
import MetaTitle from '../components/meta/MetaTitle'
|
|
3
3
|
import MetaDescription from '../components/meta/MetaDescription'
|
|
4
4
|
import SeoPreview from '../components/SeoPreview'
|
|
5
|
+
import {SeoFieldsPluginConfig} from '../plugin'
|
|
6
|
+
import {getFieldInfo} from '../utils/fieldsUtils'
|
|
5
7
|
|
|
6
|
-
export default
|
|
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
|
-
|
|
8
|
+
export default function seoFieldsSchema(config: SeoFieldsPluginConfig = {}) {
|
|
9
|
+
return defineType({
|
|
10
|
+
name: 'seoFields',
|
|
11
|
+
title: 'SEO Fields',
|
|
12
|
+
type: 'object',
|
|
13
|
+
fields: [
|
|
14
|
+
defineField({
|
|
15
|
+
name: 'robots',
|
|
16
|
+
title: 'Robots Settings',
|
|
17
|
+
type: 'robots', // Use the separate robots type here
|
|
18
|
+
}),
|
|
19
|
+
// 👇 conditionally spread preview field
|
|
20
|
+
...(config.seoPreview
|
|
21
|
+
? []
|
|
22
|
+
: [
|
|
23
|
+
defineField({
|
|
24
|
+
name: 'preview',
|
|
25
|
+
title: 'SEO Preview',
|
|
26
|
+
type: 'string',
|
|
27
|
+
components: {input: SeoPreview},
|
|
28
|
+
readOnly: true,
|
|
29
|
+
}),
|
|
30
|
+
]),
|
|
31
|
+
|
|
32
|
+
defineField({
|
|
33
|
+
name: 'title',
|
|
34
|
+
...getFieldInfo('title', config.fieldOverrides),
|
|
35
|
+
// title: 'Meta Title',
|
|
36
|
+
type: 'string',
|
|
37
|
+
// description:
|
|
38
|
+
// 'The meta title is displayed in search engine results as the clickable headline for a given result. It should be concise and accurately reflect the content of the page.',
|
|
39
|
+
components: {
|
|
40
|
+
input: MetaTitle,
|
|
41
|
+
},
|
|
42
|
+
// validation: (Rule) => Rule.max(60).warning('Meta title should be under 60 characters.'),
|
|
43
|
+
}),
|
|
44
|
+
defineField({
|
|
45
|
+
name: 'description',
|
|
46
|
+
...getFieldInfo('description', config.fieldOverrides),
|
|
47
|
+
// title: 'Meta Description',
|
|
48
|
+
// description:
|
|
49
|
+
// 'Provide a concise summary of the page content. This description may be used by search engines in search results.',
|
|
50
|
+
type: 'text',
|
|
51
|
+
rows: 3,
|
|
52
|
+
components: {
|
|
53
|
+
input: MetaDescription,
|
|
54
|
+
},
|
|
55
|
+
// validation: (Rule) => Rule.max(160).warning('Meta description should be under 160 characters.'),
|
|
56
|
+
}),
|
|
57
|
+
defineField({
|
|
58
|
+
name: 'metaImage',
|
|
59
|
+
...getFieldInfo('metaImage', config.fieldOverrides),
|
|
60
|
+
// title: 'Meta Image',
|
|
61
|
+
// description:
|
|
62
|
+
// 'Upload an image that represents the content of the page. This image may be used in social media previews and search engine results.',
|
|
63
|
+
type: 'image',
|
|
64
|
+
options: {
|
|
65
|
+
hotspot: true,
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
defineField({
|
|
69
|
+
name: 'metaAttributes',
|
|
70
|
+
title: 'Additional Meta Attributes',
|
|
71
|
+
type: 'array',
|
|
72
|
+
of: [{type: 'metaAttribute'}],
|
|
73
|
+
description:
|
|
74
|
+
'Add custom meta attributes to the head of the document for additional SEO and social media integration.',
|
|
75
|
+
}),
|
|
76
|
+
defineField({
|
|
77
|
+
name: 'keywords',
|
|
78
|
+
...getFieldInfo('keywords', config.fieldOverrides),
|
|
79
|
+
title: 'Keywords',
|
|
80
|
+
type: 'array',
|
|
81
|
+
of: [{type: 'string'}],
|
|
82
|
+
description:
|
|
83
|
+
'Add relevant keywords for this page. These keywords will be used for SEO purposes.',
|
|
84
|
+
}),
|
|
85
|
+
defineField({
|
|
86
|
+
name: 'canonicalUrl',
|
|
87
|
+
...getFieldInfo('canonicalUrl', config.fieldOverrides),
|
|
88
|
+
title: 'Canonical URL',
|
|
89
|
+
type: 'url',
|
|
90
|
+
description:
|
|
91
|
+
'Specify the canonical URL for this page. This helps prevent duplicate content issues by indicating the preferred version of a page.',
|
|
92
|
+
}),
|
|
93
|
+
defineField({
|
|
94
|
+
name: 'openGraph',
|
|
95
|
+
title: 'Open Graph Settings',
|
|
96
|
+
type: 'openGraph',
|
|
97
|
+
}),
|
|
98
|
+
defineField({
|
|
99
|
+
name: 'twitter',
|
|
100
|
+
title: 'Twitter Card Settings',
|
|
101
|
+
type: 'twitter',
|
|
102
|
+
}),
|
|
103
|
+
],
|
|
104
|
+
})
|
|
105
|
+
}
|
|
@@ -4,4 +4,15 @@ import openGraph from './openGraph'
|
|
|
4
4
|
import twitter from './twitter'
|
|
5
5
|
import robots from './robots'
|
|
6
6
|
import metaTag from './metaTag'
|
|
7
|
-
|
|
7
|
+
import {SeoFieldsPluginConfig} from '../../plugin'
|
|
8
|
+
|
|
9
|
+
export default function types(config: SeoFieldsPluginConfig = {}) {
|
|
10
|
+
return [
|
|
11
|
+
seoFields(config), // pass config here
|
|
12
|
+
openGraph,
|
|
13
|
+
twitter,
|
|
14
|
+
metaAttribute,
|
|
15
|
+
metaTag,
|
|
16
|
+
robots,
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// import {defineField, defineType} from 'sanity'
|
|
2
|
+
// import OgTitle from '../../../components/openGraph/OgTitle'
|
|
3
|
+
// import OgDescription from '../../../components/openGraph/OgDescription'
|
|
4
|
+
|
|
5
|
+
import {SeoField, SeoFieldsPluginConfig} from '../plugin'
|
|
6
|
+
|
|
7
|
+
// export default defineType({
|
|
8
|
+
// name: 'openGraph',
|
|
9
|
+
// title: 'Open Graph Settings',
|
|
10
|
+
// type: 'object',
|
|
11
|
+
// fields: [
|
|
12
|
+
// defineField({
|
|
13
|
+
// name: 'title',
|
|
14
|
+
// title: 'Open Graph Title',
|
|
15
|
+
// type: 'string',
|
|
16
|
+
// components: {
|
|
17
|
+
// input: OgTitle, // Can also wrap with a string input + preview
|
|
18
|
+
// },
|
|
19
|
+
// }),
|
|
20
|
+
// defineField({
|
|
21
|
+
// name: 'description',
|
|
22
|
+
// title: 'Open Graph Description',
|
|
23
|
+
// type: 'text',
|
|
24
|
+
// rows: 3,
|
|
25
|
+
// components: {
|
|
26
|
+
// input: OgDescription, // Can also wrap with a text area + preview
|
|
27
|
+
// },
|
|
28
|
+
// }),
|
|
29
|
+
// defineField({
|
|
30
|
+
// name: 'siteName',
|
|
31
|
+
// title: 'Open Graph Site Name',
|
|
32
|
+
// type: 'string',
|
|
33
|
+
// description: 'The name of your website. This is often the site title.',
|
|
34
|
+
// }),
|
|
35
|
+
// defineField({
|
|
36
|
+
// name: 'type',
|
|
37
|
+
// title: 'Open Graph Type',
|
|
38
|
+
// type: 'string',
|
|
39
|
+
// options: {
|
|
40
|
+
// list: [
|
|
41
|
+
// {title: 'Website', value: 'website'},
|
|
42
|
+
// {title: 'Article', value: 'article'},
|
|
43
|
+
// {title: 'Profile', value: 'profile'},
|
|
44
|
+
// {title: 'Book', value: 'book'},
|
|
45
|
+
// {title: 'Music', value: 'music'},
|
|
46
|
+
// {title: 'Video', value: 'video'},
|
|
47
|
+
// {title: 'Product', value: 'product'},
|
|
48
|
+
// ],
|
|
49
|
+
// // layout: 'radio', // Display as radio buttons
|
|
50
|
+
// },
|
|
51
|
+
// initialValue: 'website',
|
|
52
|
+
// description: 'Select the type of content for Open Graph.',
|
|
53
|
+
// }),
|
|
54
|
+
|
|
55
|
+
// // upload image or ask for url
|
|
56
|
+
// defineField({
|
|
57
|
+
// name: 'imageType',
|
|
58
|
+
// title: 'Image Type',
|
|
59
|
+
// type: 'string',
|
|
60
|
+
// options: {
|
|
61
|
+
// list: [
|
|
62
|
+
// {title: 'Upload Image', value: 'upload'},
|
|
63
|
+
// {title: 'Image URL', value: 'url'},
|
|
64
|
+
// ],
|
|
65
|
+
// },
|
|
66
|
+
// initialValue: 'upload',
|
|
67
|
+
// }),
|
|
68
|
+
// defineField({
|
|
69
|
+
// name: 'image',
|
|
70
|
+
// title: 'Open Graph Image',
|
|
71
|
+
// type: 'image',
|
|
72
|
+
// options: {
|
|
73
|
+
// hotspot: true,
|
|
74
|
+
// },
|
|
75
|
+
// hidden: ({parent}) => parent?.imageType !== 'upload',
|
|
76
|
+
// description:
|
|
77
|
+
// 'Recommended size: 1200x630px (minimum 600x315px). Max file size: 5MB. Aspect ratio 1.91:1.',
|
|
78
|
+
// }),
|
|
79
|
+
// defineField({
|
|
80
|
+
// name: 'imageUrl',
|
|
81
|
+
// title: 'Open Graph Image URL',
|
|
82
|
+
// type: 'url',
|
|
83
|
+
// hidden: ({parent}) => parent?.imageType !== 'url',
|
|
84
|
+
// description:
|
|
85
|
+
// 'Enter the full URL of the image. Ensure the image is accessible and meets the recommended size of 1200x630px (minimum 600x315px).',
|
|
86
|
+
// }),
|
|
87
|
+
// ],
|
|
88
|
+
// })
|
|
89
|
+
|
|
90
|
+
const DEFAULT_FIELD_INFO = {
|
|
91
|
+
title: {
|
|
92
|
+
title: 'Meta Title',
|
|
93
|
+
description:
|
|
94
|
+
'The meta title is displayed in search engine results as the clickable headline for a given result. It should be concise and accurately reflect the content of the page.',
|
|
95
|
+
},
|
|
96
|
+
description: {
|
|
97
|
+
title: 'Meta Description',
|
|
98
|
+
description:
|
|
99
|
+
'Provide a concise summary of the page content. This description may be used by search engines in search results.',
|
|
100
|
+
},
|
|
101
|
+
metaImage: {
|
|
102
|
+
title: 'Meta Image',
|
|
103
|
+
description:
|
|
104
|
+
'Upload an image that represents the content of the page. This image may be used in social media previews and search engine results.',
|
|
105
|
+
},
|
|
106
|
+
keywords: {
|
|
107
|
+
title: 'Keywords',
|
|
108
|
+
description:
|
|
109
|
+
'Add relevant keywords for this page. These keywords will be used for SEO purposes.',
|
|
110
|
+
},
|
|
111
|
+
canonicalUrl: {
|
|
112
|
+
title: 'Canonical URL',
|
|
113
|
+
description:
|
|
114
|
+
'Specify the canonical URL for this page. This helps prevent duplicate content issues by indicating the preferred version of a page.',
|
|
115
|
+
},
|
|
116
|
+
robots: {
|
|
117
|
+
title: 'Robots Settings',
|
|
118
|
+
description: 'Configure how search engine crawlers should index and follow links on this page.',
|
|
119
|
+
},
|
|
120
|
+
metaAttributes: {
|
|
121
|
+
title: 'Additional Meta Attributes',
|
|
122
|
+
description:
|
|
123
|
+
'Add custom meta attributes to the head of the document for additional SEO and social media integration.',
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const getFieldInfo = (
|
|
128
|
+
fieldName: string,
|
|
129
|
+
fieldOverrides: SeoFieldsPluginConfig['fieldOverrides'],
|
|
130
|
+
) => {
|
|
131
|
+
const fieldInfo =
|
|
132
|
+
(fieldOverrides && fieldOverrides[fieldName as keyof typeof fieldOverrides]) ||
|
|
133
|
+
DEFAULT_FIELD_INFO[fieldName as keyof typeof DEFAULT_FIELD_INFO]
|
|
134
|
+
return fieldInfo
|
|
135
|
+
? {title: fieldInfo.title, description: fieldInfo.description}
|
|
136
|
+
: {title: '', description: ''}
|
|
137
|
+
}
|
|
@@ -258,7 +258,7 @@ function generateSchemaJson(): JsonSchema {
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
// Convert each schema
|
|
261
|
-
schemas.forEach((schema) => {
|
|
261
|
+
schemas().forEach((schema) => {
|
|
262
262
|
if (schema.name) {
|
|
263
263
|
const jsonSchemaDefinition = convertSanitySchemaToJsonSchema(schema)
|
|
264
264
|
jsonSchema.definitions[schema.name] = jsonSchemaDefinition
|