sanity-plugin-seofields 1.8.0 → 1.9.0
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 +437 -26
- package/dist/SeoHealthTool-2COI27KI.cjs +8 -0
- package/dist/SeoHealthTool-2COI27KI.cjs.map +1 -0
- package/dist/SeoHealthTool-CWI3KB2V.js +8 -0
- package/dist/SeoHealthTool-CWI3KB2V.js.map +1 -0
- package/dist/{SeoPreview-3EXR6FD4.cjs → SeoPreview-LMZAWWOE.cjs} +35 -38
- package/dist/SeoPreview-LMZAWWOE.cjs.map +1 -0
- package/dist/{SeoPreview-4PPAF4NO.js → SeoPreview-UNQBKTQO.js} +14 -11
- package/dist/SeoPreview-UNQBKTQO.js.map +1 -0
- package/dist/chunk-3OK3S2F7.cjs +673 -0
- package/dist/chunk-3OK3S2F7.cjs.map +1 -0
- package/dist/{chunk-B5IVI5LP.cjs → chunk-5XTQRILL.cjs} +286 -236
- package/dist/chunk-5XTQRILL.cjs.map +1 -0
- package/dist/{chunk-254YHUN3.cjs → chunk-7N4MLTMR.js} +8 -6
- package/dist/chunk-7N4MLTMR.js.map +1 -0
- package/dist/{chunk-DDAAVRWG.js → chunk-A57XNQC7.cjs} +9 -4
- package/dist/chunk-A57XNQC7.cjs.map +1 -0
- package/dist/chunk-BWLJDK5J.js +624 -0
- package/dist/chunk-BWLJDK5J.js.map +1 -0
- package/dist/chunk-FUUWBQE2.cjs +195 -0
- package/dist/chunk-FUUWBQE2.cjs.map +1 -0
- package/dist/{chunk-ZBHLMQTS.cjs → chunk-HHO2AKAP.js} +44 -17
- package/dist/chunk-HHO2AKAP.js.map +1 -0
- package/dist/chunk-KIEO6QG3.js +195 -0
- package/dist/chunk-KIEO6QG3.js.map +1 -0
- package/dist/chunk-R2U7JF7U.cjs +624 -0
- package/dist/chunk-R2U7JF7U.cjs.map +1 -0
- package/dist/{chunk-VR44E62I.js → chunk-XZKQWV2H.js} +204 -33
- package/dist/chunk-XZKQWV2H.js.map +1 -0
- package/dist/{chunk-HDZZQCH7.js → chunk-Y46ACXM4.cjs} +45 -5
- package/dist/chunk-Y46ACXM4.cjs.map +1 -0
- package/dist/chunk-Z5AOUU4H.js +673 -0
- package/dist/chunk-Z5AOUU4H.js.map +1 -0
- package/dist/cli.js +27 -27
- package/dist/{component-DEXwtemT.d.ts → component-CjT1hvxh.d.ts} +2 -2
- package/dist/{component-BzI-LHPw.d.cts → component-WYh0z8as.d.cts} +2 -2
- package/dist/define-cli.cjs +2 -4
- package/dist/define-cli.cjs.map +1 -1
- package/dist/define-cli.js +4 -4
- package/dist/define-cli.js.map +1 -1
- package/dist/head.cjs +14 -0
- package/dist/head.cjs.map +1 -0
- package/dist/head.d.cts +254 -0
- package/dist/head.d.ts +254 -0
- package/dist/head.js +14 -0
- package/dist/head.js.map +1 -0
- package/dist/index.cjs +978 -367
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -374
- package/dist/index.d.ts +6 -374
- package/dist/index.js +920 -286
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +204 -455
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +8 -206
- package/dist/next.d.ts +8 -206
- package/dist/next.js +181 -111
- package/dist/next.js.map +1 -1
- package/dist/plugin-DQdThyxG.d.ts +449 -0
- package/dist/plugin-DoGeZP79.d.cts +449 -0
- package/dist/schema/next.cjs +173 -327
- package/dist/schema/next.cjs.map +1 -1
- package/dist/schema/next.d.cts +4 -4
- package/dist/schema/next.d.ts +4 -4
- package/dist/schema/next.js +172 -8
- package/dist/schema/next.js.map +1 -1
- package/dist/schema.cjs +376 -517
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +5 -5
- package/dist/schema.d.ts +5 -5
- package/dist/schema.js +216 -11
- package/dist/schema.js.map +1 -1
- package/dist/server.cjs +149 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +102 -0
- package/dist/server.d.ts +102 -0
- package/dist/server.js +149 -0
- package/dist/server.js.map +1 -0
- package/dist/{types-CW8qFdAn.d.ts → types-BAdN1RMu.d.ts} +2 -2
- package/dist/{types-B_vjMPtM.d.cts → types-C5i3KMgs.d.cts} +2 -2
- package/dist/{types-BXSCbl6p.d.cts → types-DP-DiW6f.d.cts} +2 -2
- package/dist/{types-C19cQx5D.d.ts → types-DRLUGLtX.d.ts} +2 -2
- package/dist/{types-yVmQfby9.d.cts → types-DxlPXihz.d.cts} +1 -1
- package/dist/{types-yVmQfby9.d.ts → types-DxlPXihz.d.ts} +1 -1
- package/package.json +25 -4
- package/dist/SeoHealthDashboard-AEKVVMUR-7NWV3C3Y.js +0 -4
- package/dist/SeoHealthDashboard-AEKVVMUR-7NWV3C3Y.js.map +0 -1
- package/dist/SeoHealthDashboard-AEKVVMUR-XWKJUH24.cjs +0 -10
- package/dist/SeoHealthDashboard-AEKVVMUR-XWKJUH24.cjs.map +0 -1
- package/dist/SeoHealthTool-2KKQJLJL.cjs +0 -11
- package/dist/SeoHealthTool-2KKQJLJL.cjs.map +0 -1
- package/dist/SeoHealthTool-3CUKGADZ.js +0 -5
- package/dist/SeoHealthTool-3CUKGADZ.js.map +0 -1
- package/dist/SeoPreview-3EXR6FD4.cjs.map +0 -1
- package/dist/SeoPreview-4PPAF4NO.js.map +0 -1
- package/dist/chunk-254YHUN3.cjs.map +0 -1
- package/dist/chunk-27XSYENH.js +0 -2215
- package/dist/chunk-27XSYENH.js.map +0 -1
- package/dist/chunk-B5IVI5LP.cjs.map +0 -1
- package/dist/chunk-BNXMFD3T.cjs +0 -431
- package/dist/chunk-BNXMFD3T.cjs.map +0 -1
- package/dist/chunk-DDAAVRWG.js.map +0 -1
- package/dist/chunk-HDZZQCH7.js.map +0 -1
- package/dist/chunk-P6IOWIO2.cjs +0 -480
- package/dist/chunk-P6IOWIO2.cjs.map +0 -1
- package/dist/chunk-UOCZFYYP.js +0 -407
- package/dist/chunk-UOCZFYYP.js.map +0 -1
- package/dist/chunk-VR44E62I.js.map +0 -1
- package/dist/chunk-WKXHX3GO.js +0 -424
- package/dist/chunk-WKXHX3GO.js.map +0 -1
- package/dist/chunk-XZDLJ2N6.cjs +0 -2224
- package/dist/chunk-XZDLJ2N6.cjs.map +0 -1
- package/dist/chunk-ZBHLMQTS.cjs.map +0 -1
package/dist/head.d.cts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { a as SanityImage, b as SanityImageWithAlt } from './types-DxlPXihz.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Headless CMS integration helpers for sanity-plugin-seofields
|
|
5
|
+
*
|
|
6
|
+
* Provides framework-agnostic SEO metadata utilities for use with:
|
|
7
|
+
* - Next.js App Router → buildSeoMeta() inside generateMetadata()
|
|
8
|
+
* - Next.js Pages Router → <SeoMetaTags> inside Next.js <Head>
|
|
9
|
+
* - Astro / Nuxt / Vue / SvelteKit / Remix → buildSeoHead() into native head APIs
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Structured metadata returned by buildSeoMeta(). Compatible with Next.js Metadata (App Router). */
|
|
13
|
+
interface SeoMetadata {
|
|
14
|
+
title?: string | null;
|
|
15
|
+
description?: string | null;
|
|
16
|
+
keywords?: string[];
|
|
17
|
+
robots?: {
|
|
18
|
+
index?: boolean;
|
|
19
|
+
follow?: boolean;
|
|
20
|
+
notranslate?: boolean;
|
|
21
|
+
noimageindex?: boolean;
|
|
22
|
+
googleBot?: {
|
|
23
|
+
index?: boolean;
|
|
24
|
+
follow?: boolean;
|
|
25
|
+
notranslate?: boolean;
|
|
26
|
+
noimageindex?: boolean;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
openGraph?: {
|
|
30
|
+
type?: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
title?: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
siteName?: string;
|
|
35
|
+
images?: Array<{
|
|
36
|
+
url: string;
|
|
37
|
+
width?: number;
|
|
38
|
+
height?: number;
|
|
39
|
+
alt?: string;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
twitter?: {
|
|
43
|
+
card?: string;
|
|
44
|
+
site?: string;
|
|
45
|
+
creator?: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
images?: string[];
|
|
49
|
+
};
|
|
50
|
+
alternates?: {
|
|
51
|
+
canonical?: string;
|
|
52
|
+
languages?: Record<string, string>;
|
|
53
|
+
};
|
|
54
|
+
/** Any custom meta attributes from seo.metaAttributes */
|
|
55
|
+
other?: Record<string, string>;
|
|
56
|
+
}
|
|
57
|
+
/** Plain `<meta>` tag data returned by buildSeoHead(). */
|
|
58
|
+
type SeoHeadMetaTag = {
|
|
59
|
+
name: string;
|
|
60
|
+
content: string;
|
|
61
|
+
} | {
|
|
62
|
+
property: string;
|
|
63
|
+
content: string;
|
|
64
|
+
};
|
|
65
|
+
/** Plain `<link>` tag data returned by buildSeoHead(). */
|
|
66
|
+
interface SeoHeadLinkTag {
|
|
67
|
+
rel: string;
|
|
68
|
+
href: string;
|
|
69
|
+
hreflang?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Framework-neutral head data returned by buildSeoHead().
|
|
73
|
+
*
|
|
74
|
+
* Use this in Astro, Nuxt, Vue, SvelteKit, Remix, or any frontend where you
|
|
75
|
+
* need plain values instead of React elements or Next.js Metadata.
|
|
76
|
+
*/
|
|
77
|
+
interface SeoHead {
|
|
78
|
+
title?: string | null;
|
|
79
|
+
meta: SeoHeadMetaTag[];
|
|
80
|
+
link: SeoHeadLinkTag[];
|
|
81
|
+
}
|
|
82
|
+
/** Default values used when SEO fields are missing. */
|
|
83
|
+
interface SeoMetaDefaults {
|
|
84
|
+
title?: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
siteName?: string;
|
|
87
|
+
twitterSite?: string;
|
|
88
|
+
twitterCreator?: string;
|
|
89
|
+
/** Fallback image URL when no OG / Twitter image is set. */
|
|
90
|
+
ogImage?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Permissive image shape accepted by buildSeoMeta — compatible with both the
|
|
94
|
+
* plugin's SanityImage and Sanity's code-generated image type (where `asset`
|
|
95
|
+
* and `alt` are optional).
|
|
96
|
+
*/
|
|
97
|
+
interface SeoImageInput {
|
|
98
|
+
_type?: string;
|
|
99
|
+
asset?: {
|
|
100
|
+
_ref: string;
|
|
101
|
+
_type: string;
|
|
102
|
+
_weak?: boolean;
|
|
103
|
+
[key: string]: unknown;
|
|
104
|
+
};
|
|
105
|
+
hotspot?: unknown;
|
|
106
|
+
crop?: unknown;
|
|
107
|
+
alt?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Input-compatible variant of SeoFields. Structurally matches Sanity's
|
|
111
|
+
* code-generated types (where `asset`, `alt`, `key`, and `type` are all
|
|
112
|
+
* optional), so you can pass `data.seo` from a sanityFetch result directly
|
|
113
|
+
* without any `as any` or manual casting.
|
|
114
|
+
*/
|
|
115
|
+
interface SeoFieldsInput {
|
|
116
|
+
_type?: string;
|
|
117
|
+
robots?: {
|
|
118
|
+
noIndex?: boolean | null;
|
|
119
|
+
noFollow?: boolean | null;
|
|
120
|
+
noTranslate?: boolean | null;
|
|
121
|
+
noImageIndex?: boolean | null;
|
|
122
|
+
} | null;
|
|
123
|
+
title?: string | null;
|
|
124
|
+
description?: string | null;
|
|
125
|
+
metaImage?: SeoImageInput | null;
|
|
126
|
+
metaAttributes?: Array<{
|
|
127
|
+
_key?: string;
|
|
128
|
+
key?: string;
|
|
129
|
+
value?: string;
|
|
130
|
+
type?: string;
|
|
131
|
+
}> | null;
|
|
132
|
+
keywords?: string[] | null;
|
|
133
|
+
canonicalUrl?: string | null;
|
|
134
|
+
hreflangs?: Array<{
|
|
135
|
+
locale?: string | null;
|
|
136
|
+
url?: string | null;
|
|
137
|
+
}> | null;
|
|
138
|
+
openGraph?: {
|
|
139
|
+
_type?: string;
|
|
140
|
+
url?: string | null;
|
|
141
|
+
title?: string | null;
|
|
142
|
+
description?: string | null;
|
|
143
|
+
siteName?: string | null;
|
|
144
|
+
type?: string | null;
|
|
145
|
+
imageType?: string | null;
|
|
146
|
+
image?: SeoImageInput | null;
|
|
147
|
+
imageUrl?: string | null;
|
|
148
|
+
} | null;
|
|
149
|
+
twitter?: {
|
|
150
|
+
_type?: string;
|
|
151
|
+
card?: string | null;
|
|
152
|
+
site?: string | null;
|
|
153
|
+
creator?: string | null;
|
|
154
|
+
title?: string | null;
|
|
155
|
+
description?: string | null;
|
|
156
|
+
imageType?: string | null;
|
|
157
|
+
image?: SeoImageInput | null;
|
|
158
|
+
imageUrl?: string | null;
|
|
159
|
+
} | null;
|
|
160
|
+
}
|
|
161
|
+
/** Options accepted by buildSeoMeta(). */
|
|
162
|
+
interface BuildSeoMetaOptions {
|
|
163
|
+
/**
|
|
164
|
+
* The raw SEO object from Sanity (_type excluded or included — both work).
|
|
165
|
+
* Pass `null` or `undefined` to fall back entirely to `defaults`.
|
|
166
|
+
*
|
|
167
|
+
* Accepts both the strict plugin `SeoFields` type and Sanity's code-generated
|
|
168
|
+
* type (which has all nested fields optional) without any `as any` cast.
|
|
169
|
+
*/
|
|
170
|
+
seo?: SeoFieldsInput | null;
|
|
171
|
+
/**
|
|
172
|
+
* The base URL of your site, e.g. "https://example.com".
|
|
173
|
+
* Used for canonical URL and OpenGraph URL construction.
|
|
174
|
+
*/
|
|
175
|
+
baseUrl?: string;
|
|
176
|
+
/**
|
|
177
|
+
* The path for the current page, e.g. "/about".
|
|
178
|
+
* Combined with baseUrl to produce the canonical + OG url.
|
|
179
|
+
* Defaults to "".
|
|
180
|
+
*/
|
|
181
|
+
path?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Default values used when the Sanity SEO fields are empty / missing.
|
|
184
|
+
*/
|
|
185
|
+
defaults?: SeoMetaDefaults;
|
|
186
|
+
/**
|
|
187
|
+
* Resolve a Sanity image asset to a plain URL string.
|
|
188
|
+
*
|
|
189
|
+
* @example (using @sanity/image-url)
|
|
190
|
+
* imageUrlResolver: (img) => urlFor(img).width(1200).url()
|
|
191
|
+
*/
|
|
192
|
+
imageUrlResolver?: (image: SanityImage | SanityImageWithAlt) => string | null | undefined;
|
|
193
|
+
}
|
|
194
|
+
declare const VALID_OG_TYPES: readonly ["website", "article", "profile", "book", "music", "video", "product"];
|
|
195
|
+
type OGType = (typeof VALID_OG_TYPES)[number];
|
|
196
|
+
/**
|
|
197
|
+
* Coerce an arbitrary string to a valid OpenGraph type.
|
|
198
|
+
* Falls back to "website" when the value is invalid.
|
|
199
|
+
*/
|
|
200
|
+
declare function sanitizeOGType(value?: string): OGType;
|
|
201
|
+
declare const VALID_TWITTER_CARDS: readonly ["summary", "summary_large_image", "app", "player"];
|
|
202
|
+
type TwitterCard = (typeof VALID_TWITTER_CARDS)[number];
|
|
203
|
+
/**
|
|
204
|
+
* Coerce an arbitrary string to a valid Twitter card type.
|
|
205
|
+
* Falls back to "summary_large_image" when the value is invalid.
|
|
206
|
+
*/
|
|
207
|
+
declare function sanitizeTwitterCard(value?: string): TwitterCard;
|
|
208
|
+
/**
|
|
209
|
+
* Convert a Sanity SEO object into a structured metadata object.
|
|
210
|
+
*
|
|
211
|
+
* The return value is structurally compatible with Next.js App Router's
|
|
212
|
+
* `Metadata` type, so you can return it directly from `generateMetadata()`.
|
|
213
|
+
*
|
|
214
|
+
* @example Next.js App Router
|
|
215
|
+
* ```ts
|
|
216
|
+
* import { buildSeoMeta } from 'sanity-plugin-seofields/next'
|
|
217
|
+
* import { urlFor } from '@/sanity/lib/image'
|
|
218
|
+
*
|
|
219
|
+
* export async function generateMetadata(): Promise<Metadata> {
|
|
220
|
+
* const { seo } = await sanityFetch({ query: PAGE_SEO_QUERY })
|
|
221
|
+
* return buildSeoMeta({
|
|
222
|
+
* seo,
|
|
223
|
+
* baseUrl: process.env.NEXT_PUBLIC_SITE_URL,
|
|
224
|
+
* path: '/about',
|
|
225
|
+
* defaults: { title: 'My Site', siteName: 'My Site' },
|
|
226
|
+
* imageUrlResolver: (img) => urlFor(img).width(1200).url(),
|
|
227
|
+
* })
|
|
228
|
+
* }
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
declare function buildSeoMeta(options: BuildSeoMetaOptions): SeoMetadata;
|
|
232
|
+
/**
|
|
233
|
+
* Convert Sanity SEO fields into plain head tag data.
|
|
234
|
+
*
|
|
235
|
+
* This helper is framework-neutral: it returns serializable `title`, `meta`,
|
|
236
|
+
* and `link` arrays that can be passed to Astro layouts, Nuxt/Vue `useHead`,
|
|
237
|
+
* SvelteKit `<svelte:head>`, Remix `meta()` exports, or any custom renderer.
|
|
238
|
+
*
|
|
239
|
+
* @example Astro / Nuxt / SvelteKit
|
|
240
|
+
* ```ts
|
|
241
|
+
* import { buildSeoHead } from 'sanity-plugin-seofields/head'
|
|
242
|
+
*
|
|
243
|
+
* const head = buildSeoHead({
|
|
244
|
+
* seo: page.seo,
|
|
245
|
+
* baseUrl: 'https://example.com',
|
|
246
|
+
* path: `/blog/${page.slug}`,
|
|
247
|
+
* defaults: { title: page.title, siteName: 'My Site' },
|
|
248
|
+
* imageUrlResolver: (img) => urlFor(img).width(1200).height(630).url(),
|
|
249
|
+
* })
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare function buildSeoHead(options: BuildSeoMetaOptions): SeoHead;
|
|
253
|
+
|
|
254
|
+
export { type BuildSeoMetaOptions, type SeoFieldsInput, type SeoHead, type SeoHeadLinkTag, type SeoHeadMetaTag, type SeoMetaDefaults, type SeoMetadata, buildSeoHead, buildSeoMeta, sanitizeOGType, sanitizeTwitterCard };
|
package/dist/head.d.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { a as SanityImage, b as SanityImageWithAlt } from './types-DxlPXihz.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Headless CMS integration helpers for sanity-plugin-seofields
|
|
5
|
+
*
|
|
6
|
+
* Provides framework-agnostic SEO metadata utilities for use with:
|
|
7
|
+
* - Next.js App Router → buildSeoMeta() inside generateMetadata()
|
|
8
|
+
* - Next.js Pages Router → <SeoMetaTags> inside Next.js <Head>
|
|
9
|
+
* - Astro / Nuxt / Vue / SvelteKit / Remix → buildSeoHead() into native head APIs
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Structured metadata returned by buildSeoMeta(). Compatible with Next.js Metadata (App Router). */
|
|
13
|
+
interface SeoMetadata {
|
|
14
|
+
title?: string | null;
|
|
15
|
+
description?: string | null;
|
|
16
|
+
keywords?: string[];
|
|
17
|
+
robots?: {
|
|
18
|
+
index?: boolean;
|
|
19
|
+
follow?: boolean;
|
|
20
|
+
notranslate?: boolean;
|
|
21
|
+
noimageindex?: boolean;
|
|
22
|
+
googleBot?: {
|
|
23
|
+
index?: boolean;
|
|
24
|
+
follow?: boolean;
|
|
25
|
+
notranslate?: boolean;
|
|
26
|
+
noimageindex?: boolean;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
openGraph?: {
|
|
30
|
+
type?: string;
|
|
31
|
+
url?: string;
|
|
32
|
+
title?: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
siteName?: string;
|
|
35
|
+
images?: Array<{
|
|
36
|
+
url: string;
|
|
37
|
+
width?: number;
|
|
38
|
+
height?: number;
|
|
39
|
+
alt?: string;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
twitter?: {
|
|
43
|
+
card?: string;
|
|
44
|
+
site?: string;
|
|
45
|
+
creator?: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
images?: string[];
|
|
49
|
+
};
|
|
50
|
+
alternates?: {
|
|
51
|
+
canonical?: string;
|
|
52
|
+
languages?: Record<string, string>;
|
|
53
|
+
};
|
|
54
|
+
/** Any custom meta attributes from seo.metaAttributes */
|
|
55
|
+
other?: Record<string, string>;
|
|
56
|
+
}
|
|
57
|
+
/** Plain `<meta>` tag data returned by buildSeoHead(). */
|
|
58
|
+
type SeoHeadMetaTag = {
|
|
59
|
+
name: string;
|
|
60
|
+
content: string;
|
|
61
|
+
} | {
|
|
62
|
+
property: string;
|
|
63
|
+
content: string;
|
|
64
|
+
};
|
|
65
|
+
/** Plain `<link>` tag data returned by buildSeoHead(). */
|
|
66
|
+
interface SeoHeadLinkTag {
|
|
67
|
+
rel: string;
|
|
68
|
+
href: string;
|
|
69
|
+
hreflang?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Framework-neutral head data returned by buildSeoHead().
|
|
73
|
+
*
|
|
74
|
+
* Use this in Astro, Nuxt, Vue, SvelteKit, Remix, or any frontend where you
|
|
75
|
+
* need plain values instead of React elements or Next.js Metadata.
|
|
76
|
+
*/
|
|
77
|
+
interface SeoHead {
|
|
78
|
+
title?: string | null;
|
|
79
|
+
meta: SeoHeadMetaTag[];
|
|
80
|
+
link: SeoHeadLinkTag[];
|
|
81
|
+
}
|
|
82
|
+
/** Default values used when SEO fields are missing. */
|
|
83
|
+
interface SeoMetaDefaults {
|
|
84
|
+
title?: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
siteName?: string;
|
|
87
|
+
twitterSite?: string;
|
|
88
|
+
twitterCreator?: string;
|
|
89
|
+
/** Fallback image URL when no OG / Twitter image is set. */
|
|
90
|
+
ogImage?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Permissive image shape accepted by buildSeoMeta — compatible with both the
|
|
94
|
+
* plugin's SanityImage and Sanity's code-generated image type (where `asset`
|
|
95
|
+
* and `alt` are optional).
|
|
96
|
+
*/
|
|
97
|
+
interface SeoImageInput {
|
|
98
|
+
_type?: string;
|
|
99
|
+
asset?: {
|
|
100
|
+
_ref: string;
|
|
101
|
+
_type: string;
|
|
102
|
+
_weak?: boolean;
|
|
103
|
+
[key: string]: unknown;
|
|
104
|
+
};
|
|
105
|
+
hotspot?: unknown;
|
|
106
|
+
crop?: unknown;
|
|
107
|
+
alt?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Input-compatible variant of SeoFields. Structurally matches Sanity's
|
|
111
|
+
* code-generated types (where `asset`, `alt`, `key`, and `type` are all
|
|
112
|
+
* optional), so you can pass `data.seo` from a sanityFetch result directly
|
|
113
|
+
* without any `as any` or manual casting.
|
|
114
|
+
*/
|
|
115
|
+
interface SeoFieldsInput {
|
|
116
|
+
_type?: string;
|
|
117
|
+
robots?: {
|
|
118
|
+
noIndex?: boolean | null;
|
|
119
|
+
noFollow?: boolean | null;
|
|
120
|
+
noTranslate?: boolean | null;
|
|
121
|
+
noImageIndex?: boolean | null;
|
|
122
|
+
} | null;
|
|
123
|
+
title?: string | null;
|
|
124
|
+
description?: string | null;
|
|
125
|
+
metaImage?: SeoImageInput | null;
|
|
126
|
+
metaAttributes?: Array<{
|
|
127
|
+
_key?: string;
|
|
128
|
+
key?: string;
|
|
129
|
+
value?: string;
|
|
130
|
+
type?: string;
|
|
131
|
+
}> | null;
|
|
132
|
+
keywords?: string[] | null;
|
|
133
|
+
canonicalUrl?: string | null;
|
|
134
|
+
hreflangs?: Array<{
|
|
135
|
+
locale?: string | null;
|
|
136
|
+
url?: string | null;
|
|
137
|
+
}> | null;
|
|
138
|
+
openGraph?: {
|
|
139
|
+
_type?: string;
|
|
140
|
+
url?: string | null;
|
|
141
|
+
title?: string | null;
|
|
142
|
+
description?: string | null;
|
|
143
|
+
siteName?: string | null;
|
|
144
|
+
type?: string | null;
|
|
145
|
+
imageType?: string | null;
|
|
146
|
+
image?: SeoImageInput | null;
|
|
147
|
+
imageUrl?: string | null;
|
|
148
|
+
} | null;
|
|
149
|
+
twitter?: {
|
|
150
|
+
_type?: string;
|
|
151
|
+
card?: string | null;
|
|
152
|
+
site?: string | null;
|
|
153
|
+
creator?: string | null;
|
|
154
|
+
title?: string | null;
|
|
155
|
+
description?: string | null;
|
|
156
|
+
imageType?: string | null;
|
|
157
|
+
image?: SeoImageInput | null;
|
|
158
|
+
imageUrl?: string | null;
|
|
159
|
+
} | null;
|
|
160
|
+
}
|
|
161
|
+
/** Options accepted by buildSeoMeta(). */
|
|
162
|
+
interface BuildSeoMetaOptions {
|
|
163
|
+
/**
|
|
164
|
+
* The raw SEO object from Sanity (_type excluded or included — both work).
|
|
165
|
+
* Pass `null` or `undefined` to fall back entirely to `defaults`.
|
|
166
|
+
*
|
|
167
|
+
* Accepts both the strict plugin `SeoFields` type and Sanity's code-generated
|
|
168
|
+
* type (which has all nested fields optional) without any `as any` cast.
|
|
169
|
+
*/
|
|
170
|
+
seo?: SeoFieldsInput | null;
|
|
171
|
+
/**
|
|
172
|
+
* The base URL of your site, e.g. "https://example.com".
|
|
173
|
+
* Used for canonical URL and OpenGraph URL construction.
|
|
174
|
+
*/
|
|
175
|
+
baseUrl?: string;
|
|
176
|
+
/**
|
|
177
|
+
* The path for the current page, e.g. "/about".
|
|
178
|
+
* Combined with baseUrl to produce the canonical + OG url.
|
|
179
|
+
* Defaults to "".
|
|
180
|
+
*/
|
|
181
|
+
path?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Default values used when the Sanity SEO fields are empty / missing.
|
|
184
|
+
*/
|
|
185
|
+
defaults?: SeoMetaDefaults;
|
|
186
|
+
/**
|
|
187
|
+
* Resolve a Sanity image asset to a plain URL string.
|
|
188
|
+
*
|
|
189
|
+
* @example (using @sanity/image-url)
|
|
190
|
+
* imageUrlResolver: (img) => urlFor(img).width(1200).url()
|
|
191
|
+
*/
|
|
192
|
+
imageUrlResolver?: (image: SanityImage | SanityImageWithAlt) => string | null | undefined;
|
|
193
|
+
}
|
|
194
|
+
declare const VALID_OG_TYPES: readonly ["website", "article", "profile", "book", "music", "video", "product"];
|
|
195
|
+
type OGType = (typeof VALID_OG_TYPES)[number];
|
|
196
|
+
/**
|
|
197
|
+
* Coerce an arbitrary string to a valid OpenGraph type.
|
|
198
|
+
* Falls back to "website" when the value is invalid.
|
|
199
|
+
*/
|
|
200
|
+
declare function sanitizeOGType(value?: string): OGType;
|
|
201
|
+
declare const VALID_TWITTER_CARDS: readonly ["summary", "summary_large_image", "app", "player"];
|
|
202
|
+
type TwitterCard = (typeof VALID_TWITTER_CARDS)[number];
|
|
203
|
+
/**
|
|
204
|
+
* Coerce an arbitrary string to a valid Twitter card type.
|
|
205
|
+
* Falls back to "summary_large_image" when the value is invalid.
|
|
206
|
+
*/
|
|
207
|
+
declare function sanitizeTwitterCard(value?: string): TwitterCard;
|
|
208
|
+
/**
|
|
209
|
+
* Convert a Sanity SEO object into a structured metadata object.
|
|
210
|
+
*
|
|
211
|
+
* The return value is structurally compatible with Next.js App Router's
|
|
212
|
+
* `Metadata` type, so you can return it directly from `generateMetadata()`.
|
|
213
|
+
*
|
|
214
|
+
* @example Next.js App Router
|
|
215
|
+
* ```ts
|
|
216
|
+
* import { buildSeoMeta } from 'sanity-plugin-seofields/next'
|
|
217
|
+
* import { urlFor } from '@/sanity/lib/image'
|
|
218
|
+
*
|
|
219
|
+
* export async function generateMetadata(): Promise<Metadata> {
|
|
220
|
+
* const { seo } = await sanityFetch({ query: PAGE_SEO_QUERY })
|
|
221
|
+
* return buildSeoMeta({
|
|
222
|
+
* seo,
|
|
223
|
+
* baseUrl: process.env.NEXT_PUBLIC_SITE_URL,
|
|
224
|
+
* path: '/about',
|
|
225
|
+
* defaults: { title: 'My Site', siteName: 'My Site' },
|
|
226
|
+
* imageUrlResolver: (img) => urlFor(img).width(1200).url(),
|
|
227
|
+
* })
|
|
228
|
+
* }
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
declare function buildSeoMeta(options: BuildSeoMetaOptions): SeoMetadata;
|
|
232
|
+
/**
|
|
233
|
+
* Convert Sanity SEO fields into plain head tag data.
|
|
234
|
+
*
|
|
235
|
+
* This helper is framework-neutral: it returns serializable `title`, `meta`,
|
|
236
|
+
* and `link` arrays that can be passed to Astro layouts, Nuxt/Vue `useHead`,
|
|
237
|
+
* SvelteKit `<svelte:head>`, Remix `meta()` exports, or any custom renderer.
|
|
238
|
+
*
|
|
239
|
+
* @example Astro / Nuxt / SvelteKit
|
|
240
|
+
* ```ts
|
|
241
|
+
* import { buildSeoHead } from 'sanity-plugin-seofields/head'
|
|
242
|
+
*
|
|
243
|
+
* const head = buildSeoHead({
|
|
244
|
+
* seo: page.seo,
|
|
245
|
+
* baseUrl: 'https://example.com',
|
|
246
|
+
* path: `/blog/${page.slug}`,
|
|
247
|
+
* defaults: { title: page.title, siteName: 'My Site' },
|
|
248
|
+
* imageUrlResolver: (img) => urlFor(img).width(1200).height(630).url(),
|
|
249
|
+
* })
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare function buildSeoHead(options: BuildSeoMetaOptions): SeoHead;
|
|
253
|
+
|
|
254
|
+
export { type BuildSeoMetaOptions, type SeoFieldsInput, type SeoHead, type SeoHeadLinkTag, type SeoHeadMetaTag, type SeoMetaDefaults, type SeoMetadata, buildSeoHead, buildSeoMeta, sanitizeOGType, sanitizeTwitterCard };
|
package/dist/head.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildSeoHead,
|
|
3
|
+
buildSeoMeta,
|
|
4
|
+
sanitizeOGType,
|
|
5
|
+
sanitizeTwitterCard
|
|
6
|
+
} from "./chunk-KIEO6QG3.js";
|
|
7
|
+
import "./chunk-7N4MLTMR.js";
|
|
8
|
+
export {
|
|
9
|
+
buildSeoHead,
|
|
10
|
+
buildSeoMeta,
|
|
11
|
+
sanitizeOGType,
|
|
12
|
+
sanitizeTwitterCard
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=head.js.map
|
package/dist/head.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|