sanity-plugin-seofields 1.0.1 → 1.0.3
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 +88 -6
- package/dist/index.d.mts +32 -19
- package/dist/index.d.ts +32 -19
- package/dist/index.js +254 -201
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +256 -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 +7 -2
- package/src/plugin.ts +24 -18
- package/src/schemas/index.ts +101 -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/README.md
CHANGED
|
@@ -37,7 +37,7 @@ Add the plugin to your `sanity.config.ts` (or `.js`) file:
|
|
|
37
37
|
|
|
38
38
|
```typescript
|
|
39
39
|
import {defineConfig} from 'sanity'
|
|
40
|
-
import
|
|
40
|
+
import seofields from 'sanity-plugin-seofields'
|
|
41
41
|
|
|
42
42
|
export default defineConfig({
|
|
43
43
|
name: 'your-project',
|
|
@@ -140,17 +140,76 @@ export default defineType({
|
|
|
140
140
|
### Basic Configuration
|
|
141
141
|
|
|
142
142
|
```typescript
|
|
143
|
-
import
|
|
143
|
+
import seofields from 'sanity-plugin-seofields'
|
|
144
|
+
|
|
145
|
+
export default defineConfig({
|
|
146
|
+
plugins: [
|
|
147
|
+
seofields(), // Use default configuration
|
|
148
|
+
],
|
|
149
|
+
})
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Advanced Configuration
|
|
153
|
+
|
|
154
|
+
You can customize field titles and descriptions, and control SEO preview functionality:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import seofields, {SeoFieldsPluginConfig} from 'sanity-plugin-seofields'
|
|
144
158
|
|
|
145
159
|
export default defineConfig({
|
|
146
160
|
plugins: [
|
|
147
161
|
seofields({
|
|
148
|
-
//
|
|
149
|
-
|
|
162
|
+
seoPreview: true, // Enable/disable SEO preview (default: true)
|
|
163
|
+
fieldOverrides: {
|
|
164
|
+
title: {
|
|
165
|
+
title: 'Page Title',
|
|
166
|
+
description: 'The main title that appears in search results',
|
|
167
|
+
},
|
|
168
|
+
description: {
|
|
169
|
+
title: 'Meta Description',
|
|
170
|
+
description: 'A brief description of the page content for search engines',
|
|
171
|
+
},
|
|
172
|
+
canonicalUrl: {
|
|
173
|
+
title: 'Canonical URL',
|
|
174
|
+
description: 'The preferred URL for this page to avoid duplicate content issues',
|
|
175
|
+
},
|
|
176
|
+
metaImage: {
|
|
177
|
+
title: 'Social Media Image',
|
|
178
|
+
description: 'Image used when sharing this page on social media',
|
|
179
|
+
},
|
|
180
|
+
keywords: {
|
|
181
|
+
title: 'SEO Keywords',
|
|
182
|
+
description: 'Keywords that describe the content of this page',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
} satisfies SeoFieldsPluginConfig),
|
|
150
186
|
],
|
|
151
187
|
})
|
|
152
188
|
```
|
|
153
189
|
|
|
190
|
+
### Configuration Options
|
|
191
|
+
|
|
192
|
+
| Option | Type | Default | Description |
|
|
193
|
+
| ---------------- | --------- | ------- | ------------------------------------------- |
|
|
194
|
+
| `seoPreview` | `boolean` | `true` | Enable/disable the live SEO preview feature |
|
|
195
|
+
| `fieldOverrides` | `object` | `{}` | Customize field titles and descriptions |
|
|
196
|
+
|
|
197
|
+
#### Field Configuration
|
|
198
|
+
|
|
199
|
+
Each field in the `fieldOverrides` object can have:
|
|
200
|
+
|
|
201
|
+
- `title` - Custom title for the field
|
|
202
|
+
- `description` - Custom description/help text for the field
|
|
203
|
+
|
|
204
|
+
**Available field keys:**
|
|
205
|
+
|
|
206
|
+
- `title`
|
|
207
|
+
- `description`
|
|
208
|
+
- `canonicalUrl`
|
|
209
|
+
- `metaImage`
|
|
210
|
+
- `keywords`
|
|
211
|
+
- `metaAttributes`
|
|
212
|
+
|
|
154
213
|
### Field Specifications
|
|
155
214
|
|
|
156
215
|
#### Meta Title
|
|
@@ -183,7 +242,27 @@ export default defineConfig({
|
|
|
183
242
|
The plugin includes full TypeScript support:
|
|
184
243
|
|
|
185
244
|
```typescript
|
|
186
|
-
import type {
|
|
245
|
+
import type {
|
|
246
|
+
SeoFields,
|
|
247
|
+
OpenGraphSettings,
|
|
248
|
+
TwitterCardSettings,
|
|
249
|
+
SeoFieldsPluginConfig,
|
|
250
|
+
} from 'sanity-plugin-seofields'
|
|
251
|
+
|
|
252
|
+
// Plugin configuration
|
|
253
|
+
const pluginConfig: SeoFieldsPluginConfig = {
|
|
254
|
+
seoPreview: true,
|
|
255
|
+
fields: {
|
|
256
|
+
title: {
|
|
257
|
+
title: 'Page Title',
|
|
258
|
+
description: 'The main title for search engines',
|
|
259
|
+
},
|
|
260
|
+
description: {
|
|
261
|
+
title: 'Meta Description',
|
|
262
|
+
description: 'Brief description for search results',
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
}
|
|
187
266
|
|
|
188
267
|
// Use in your document interfaces
|
|
189
268
|
interface PageDocument {
|
|
@@ -211,6 +290,9 @@ const seoData: SeoFields = {
|
|
|
211
290
|
```typescript
|
|
212
291
|
import type {
|
|
213
292
|
SeoFields,
|
|
293
|
+
SeoFieldsPluginConfig,
|
|
294
|
+
SeoFieldConfig,
|
|
295
|
+
SeoFieldKeys,
|
|
214
296
|
OpenGraphSettings,
|
|
215
297
|
TwitterCardSettings,
|
|
216
298
|
MetaAttribute,
|
|
@@ -338,7 +420,7 @@ export function SEO({seo}: SEOProps) {
|
|
|
338
420
|
### Main Export
|
|
339
421
|
|
|
340
422
|
```typescript
|
|
341
|
-
import
|
|
423
|
+
import seofields from 'sanity-plugin-seofields'
|
|
342
424
|
```
|
|
343
425
|
|
|
344
426
|
### Schema Types
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import {ObjectDefinition} from 'sanity'
|
|
|
2
2
|
import {Plugin as Plugin_2} from 'sanity'
|
|
3
3
|
import {PreviewConfig} from 'sanity'
|
|
4
4
|
|
|
5
|
-
export declare
|
|
5
|
+
export declare function allSchemas(config?: SeoFieldsPluginConfig): (
|
|
6
6
|
| ({
|
|
7
7
|
type: 'object'
|
|
8
8
|
name: 'seoFields'
|
|
@@ -99,8 +99,6 @@ export declare const metaTagSchema: {
|
|
|
99
99
|
preview?: PreviewConfig<Record<string, string>, Record<never, any>> | undefined
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
declare interface MyPluginConfig {}
|
|
103
|
-
|
|
104
102
|
export declare const openGraphSchema: {
|
|
105
103
|
type: 'object'
|
|
106
104
|
name: 'openGraph'
|
|
@@ -119,6 +117,13 @@ export declare interface OpenGraphSettings {
|
|
|
119
117
|
imageUrl?: string
|
|
120
118
|
}
|
|
121
119
|
|
|
120
|
+
export declare const robotsSchema: {
|
|
121
|
+
type: 'object'
|
|
122
|
+
name: 'robots'
|
|
123
|
+
} & Omit<ObjectDefinition, 'preview'> & {
|
|
124
|
+
preview?: PreviewConfig<Record<string, string>, Record<never, any>> | undefined
|
|
125
|
+
}
|
|
126
|
+
|
|
122
127
|
export declare interface RobotsSettings {
|
|
123
128
|
noIndex?: boolean
|
|
124
129
|
noFollow?: boolean
|
|
@@ -149,6 +154,19 @@ export declare interface SanityImageWithAlt extends SanityImage {
|
|
|
149
154
|
alt: string
|
|
150
155
|
}
|
|
151
156
|
|
|
157
|
+
export declare interface SeoFieldConfig {
|
|
158
|
+
title?: string
|
|
159
|
+
description?: string
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export declare type SeoFieldKeys =
|
|
163
|
+
| 'title'
|
|
164
|
+
| 'description'
|
|
165
|
+
| 'canonicalUrl'
|
|
166
|
+
| 'metaImage'
|
|
167
|
+
| 'keywords'
|
|
168
|
+
| 'metaAttributes'
|
|
169
|
+
|
|
152
170
|
export declare interface SeoFields {
|
|
153
171
|
_type: 'seoFields'
|
|
154
172
|
robots?: RobotsSettings
|
|
@@ -162,22 +180,17 @@ export declare interface SeoFields {
|
|
|
162
180
|
twitter?: TwitterCardSettings
|
|
163
181
|
}
|
|
164
182
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
export declare const seofields: Plugin_2<void | MyPluginConfig>
|
|
179
|
-
|
|
180
|
-
export declare const seoFieldsSchema: {
|
|
183
|
+
declare const seofields: Plugin_2<void | SeoFieldsPluginConfig>
|
|
184
|
+
export default seofields
|
|
185
|
+
|
|
186
|
+
export declare interface SeoFieldsPluginConfig {
|
|
187
|
+
seoPreview?: boolean
|
|
188
|
+
fieldOverrides?: {
|
|
189
|
+
[key in SeoFieldKeys]?: SeoFieldConfig
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export declare function seoFieldsSchema(config?: SeoFieldsPluginConfig): {
|
|
181
194
|
type: 'object'
|
|
182
195
|
name: 'seoFields'
|
|
183
196
|
} & Omit<ObjectDefinition, 'preview'> & {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {ObjectDefinition} from 'sanity'
|
|
|
2
2
|
import {Plugin as Plugin_2} from 'sanity'
|
|
3
3
|
import {PreviewConfig} from 'sanity'
|
|
4
4
|
|
|
5
|
-
export declare
|
|
5
|
+
export declare function allSchemas(config?: SeoFieldsPluginConfig): (
|
|
6
6
|
| ({
|
|
7
7
|
type: 'object'
|
|
8
8
|
name: 'seoFields'
|
|
@@ -99,8 +99,6 @@ export declare const metaTagSchema: {
|
|
|
99
99
|
preview?: PreviewConfig<Record<string, string>, Record<never, any>> | undefined
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
declare interface MyPluginConfig {}
|
|
103
|
-
|
|
104
102
|
export declare const openGraphSchema: {
|
|
105
103
|
type: 'object'
|
|
106
104
|
name: 'openGraph'
|
|
@@ -119,6 +117,13 @@ export declare interface OpenGraphSettings {
|
|
|
119
117
|
imageUrl?: string
|
|
120
118
|
}
|
|
121
119
|
|
|
120
|
+
export declare const robotsSchema: {
|
|
121
|
+
type: 'object'
|
|
122
|
+
name: 'robots'
|
|
123
|
+
} & Omit<ObjectDefinition, 'preview'> & {
|
|
124
|
+
preview?: PreviewConfig<Record<string, string>, Record<never, any>> | undefined
|
|
125
|
+
}
|
|
126
|
+
|
|
122
127
|
export declare interface RobotsSettings {
|
|
123
128
|
noIndex?: boolean
|
|
124
129
|
noFollow?: boolean
|
|
@@ -149,6 +154,19 @@ export declare interface SanityImageWithAlt extends SanityImage {
|
|
|
149
154
|
alt: string
|
|
150
155
|
}
|
|
151
156
|
|
|
157
|
+
export declare interface SeoFieldConfig {
|
|
158
|
+
title?: string
|
|
159
|
+
description?: string
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export declare type SeoFieldKeys =
|
|
163
|
+
| 'title'
|
|
164
|
+
| 'description'
|
|
165
|
+
| 'canonicalUrl'
|
|
166
|
+
| 'metaImage'
|
|
167
|
+
| 'keywords'
|
|
168
|
+
| 'metaAttributes'
|
|
169
|
+
|
|
152
170
|
export declare interface SeoFields {
|
|
153
171
|
_type: 'seoFields'
|
|
154
172
|
robots?: RobotsSettings
|
|
@@ -162,22 +180,17 @@ export declare interface SeoFields {
|
|
|
162
180
|
twitter?: TwitterCardSettings
|
|
163
181
|
}
|
|
164
182
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
export declare const seofields: Plugin_2<void | MyPluginConfig>
|
|
179
|
-
|
|
180
|
-
export declare const seoFieldsSchema: {
|
|
183
|
+
declare const seofields: Plugin_2<void | SeoFieldsPluginConfig>
|
|
184
|
+
export default seofields
|
|
185
|
+
|
|
186
|
+
export declare interface SeoFieldsPluginConfig {
|
|
187
|
+
seoPreview?: boolean
|
|
188
|
+
fieldOverrides?: {
|
|
189
|
+
[key in SeoFieldKeys]?: SeoFieldConfig
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export declare function seoFieldsSchema(config?: SeoFieldsPluginConfig): {
|
|
181
194
|
type: 'object'
|
|
182
195
|
name: 'seoFields'
|
|
183
196
|
} & Omit<ObjectDefinition, 'preview'> & {
|