sanity-plugin-seofields 1.2.4 → 1.2.6
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/dist/index.cjs +2604 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +422 -0
- package/dist/index.d.ts +339 -492
- package/dist/index.js +1284 -2013
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +182 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +241 -0
- package/dist/next.d.ts +202 -295
- package/dist/next.js +110 -70
- package/dist/next.js.map +1 -1
- package/dist/types-B91ena4g.d.cts +89 -0
- package/dist/types-B91ena4g.d.ts +89 -0
- package/package.json +37 -18
- package/dist/index.d.mts +0 -575
- package/dist/index.mjs +0 -3292
- package/dist/index.mjs.map +0 -1
- package/dist/next.d.mts +0 -334
- package/dist/next.mjs +0 -102
- package/dist/next.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/components/SeoHealthDashboard.tsx +0 -1568
- package/src/components/SeoHealthPane.tsx +0 -81
- package/src/components/SeoHealthTool.tsx +0 -11
- package/src/components/SeoPreview.tsx +0 -178
- package/src/components/meta/MetaDescription.tsx +0 -39
- package/src/components/meta/MetaTitle.tsx +0 -44
- package/src/components/openGraph/OgDescription.tsx +0 -46
- package/src/components/openGraph/OgTitle.tsx +0 -45
- package/src/components/twitter/twitterDescription.tsx +0 -45
- package/src/components/twitter/twitterTitle.tsx +0 -45
- package/src/helpers/SeoMetaTags.tsx +0 -154
- package/src/helpers/seoMeta.ts +0 -283
- package/src/index.ts +0 -26
- package/src/next.ts +0 -12
- package/src/plugin.ts +0 -344
- package/src/schemas/index.ts +0 -121
- package/src/schemas/types/index.ts +0 -20
- package/src/schemas/types/metaAttribute/index.ts +0 -60
- package/src/schemas/types/metaTag/index.ts +0 -17
- package/src/schemas/types/openGraph/index.ts +0 -114
- package/src/schemas/types/robots/index.ts +0 -26
- package/src/schemas/types/twitter/index.ts +0 -108
- package/src/types.ts +0 -108
- package/src/utils/fieldsUtils.ts +0 -160
- package/src/utils/seoUtils.ts +0 -423
- package/src/utils/utils.ts +0 -9
- package/v2-incompatible.js +0 -11
package/dist/next.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/helpers/seoMeta.ts
|
|
19
|
+
var VALID_OG_TYPES = [
|
|
9
20
|
"website",
|
|
10
21
|
"article",
|
|
11
22
|
"profile",
|
|
@@ -15,91 +26,120 @@ const VALID_OG_TYPES = [
|
|
|
15
26
|
"product"
|
|
16
27
|
];
|
|
17
28
|
function sanitizeOGType(value) {
|
|
18
|
-
|
|
29
|
+
if (value && VALID_OG_TYPES.includes(value)) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
return "website";
|
|
19
33
|
}
|
|
20
|
-
|
|
34
|
+
var VALID_TWITTER_CARDS = ["summary", "summary_large_image", "app", "player"];
|
|
21
35
|
function sanitizeTwitterCard(value) {
|
|
22
|
-
|
|
36
|
+
if (value && VALID_TWITTER_CARDS.includes(value)) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
return "summary_large_image";
|
|
23
40
|
}
|
|
24
41
|
function buildSeoMeta(options) {
|
|
25
|
-
|
|
42
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
43
|
+
const { seo, baseUrl = "", path = "", defaults = {}, imageUrlResolver } = options;
|
|
44
|
+
const normalizedBase = baseUrl.replace(/\/+$/, "");
|
|
45
|
+
const normalizedPath = path.replace(/^\/+/, "");
|
|
46
|
+
const fullUrl = [normalizedBase, normalizedPath].filter(Boolean).join("/");
|
|
26
47
|
let ogImageURL = defaults.ogImage || "";
|
|
27
|
-
seo
|
|
48
|
+
if (((_a = seo == null ? void 0 : seo.openGraph) == null ? void 0 : _a.imageType) === "url" && seo.openGraph.imageUrl) {
|
|
49
|
+
ogImageURL = seo.openGraph.imageUrl;
|
|
50
|
+
} else if (((_b = seo == null ? void 0 : seo.openGraph) == null ? void 0 : _b.image) && imageUrlResolver) {
|
|
51
|
+
ogImageURL = imageUrlResolver(seo.openGraph.image) || ogImageURL;
|
|
52
|
+
}
|
|
28
53
|
let twitterImageURL = ogImageURL;
|
|
29
|
-
seo
|
|
54
|
+
if (((_c = seo == null ? void 0 : seo.twitter) == null ? void 0 : _c.imageType) === "url" && seo.twitter.imageUrl) {
|
|
55
|
+
twitterImageURL = seo.twitter.imageUrl;
|
|
56
|
+
} else if (((_d = seo == null ? void 0 : seo.twitter) == null ? void 0 : _d.image) && imageUrlResolver) {
|
|
57
|
+
twitterImageURL = imageUrlResolver(seo.twitter.image) || twitterImageURL;
|
|
58
|
+
}
|
|
30
59
|
const other = {};
|
|
31
|
-
if (Array.isArray(seo
|
|
32
|
-
for (const attr of seo.metaAttributes)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
60
|
+
if (Array.isArray(seo == null ? void 0 : seo.metaAttributes)) {
|
|
61
|
+
for (const attr of seo.metaAttributes) {
|
|
62
|
+
if (attr.key && attr.value) {
|
|
63
|
+
other[attr.key] = attr.value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const ogUrl = ((_e = seo == null ? void 0 : seo.openGraph) == null ? void 0 : _e.url) || fullUrl;
|
|
68
|
+
return __spreadValues({
|
|
69
|
+
title: (_g = (_f = seo == null ? void 0 : seo.title) != null ? _f : defaults.title) != null ? _g : null,
|
|
70
|
+
description: (_i = (_h = seo == null ? void 0 : seo.description) != null ? _h : defaults.description) != null ? _i : null,
|
|
71
|
+
keywords: ((_j = seo == null ? void 0 : seo.keywords) == null ? void 0 : _j.length) ? seo.keywords : void 0,
|
|
39
72
|
robots: {
|
|
40
|
-
index: !seo
|
|
41
|
-
follow: !seo
|
|
73
|
+
index: !((_k = seo == null ? void 0 : seo.robots) == null ? void 0 : _k.noIndex),
|
|
74
|
+
follow: !((_l = seo == null ? void 0 : seo.robots) == null ? void 0 : _l.noFollow),
|
|
42
75
|
googleBot: {
|
|
43
|
-
index: !seo
|
|
44
|
-
follow: !seo
|
|
76
|
+
index: !((_m = seo == null ? void 0 : seo.robots) == null ? void 0 : _m.noIndex),
|
|
77
|
+
follow: !((_n = seo == null ? void 0 : seo.robots) == null ? void 0 : _n.noFollow)
|
|
45
78
|
}
|
|
46
79
|
},
|
|
47
80
|
openGraph: {
|
|
48
|
-
type: sanitizeOGType(seo
|
|
81
|
+
type: sanitizeOGType((_p = (_o = seo == null ? void 0 : seo.openGraph) == null ? void 0 : _o.type) != null ? _p : void 0),
|
|
49
82
|
url: ogUrl || void 0,
|
|
50
|
-
title: seo
|
|
51
|
-
description: seo
|
|
52
|
-
siteName: seo
|
|
83
|
+
title: (_r = (_q = seo == null ? void 0 : seo.openGraph) == null ? void 0 : _q.title) != null ? _r : defaults.title,
|
|
84
|
+
description: (_t = (_s = seo == null ? void 0 : seo.openGraph) == null ? void 0 : _s.description) != null ? _t : defaults.description,
|
|
85
|
+
siteName: (_v = (_u = seo == null ? void 0 : seo.openGraph) == null ? void 0 : _u.siteName) != null ? _v : defaults.siteName,
|
|
53
86
|
images: ogImageURL ? [{ url: ogImageURL }] : []
|
|
54
87
|
},
|
|
55
88
|
twitter: {
|
|
56
|
-
card: sanitizeTwitterCard(seo
|
|
57
|
-
site: seo
|
|
58
|
-
creator: seo
|
|
59
|
-
title: seo
|
|
60
|
-
description: seo
|
|
89
|
+
card: sanitizeTwitterCard((_x = (_w = seo == null ? void 0 : seo.twitter) == null ? void 0 : _w.card) != null ? _x : void 0),
|
|
90
|
+
site: (_z = (_y = seo == null ? void 0 : seo.twitter) == null ? void 0 : _y.site) != null ? _z : defaults.twitterSite,
|
|
91
|
+
creator: (_B = (_A = seo == null ? void 0 : seo.twitter) == null ? void 0 : _A.creator) != null ? _B : defaults.twitterCreator,
|
|
92
|
+
title: (_D = (_C = seo == null ? void 0 : seo.twitter) == null ? void 0 : _C.title) != null ? _D : defaults.title,
|
|
93
|
+
description: (_F = (_E = seo == null ? void 0 : seo.twitter) == null ? void 0 : _E.description) != null ? _F : defaults.description,
|
|
61
94
|
images: twitterImageURL ? [twitterImageURL] : []
|
|
62
95
|
},
|
|
63
96
|
alternates: {
|
|
64
97
|
canonical: fullUrl || void 0
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
};
|
|
98
|
+
}
|
|
99
|
+
}, Object.keys(other).length > 0 ? { other } : {});
|
|
68
100
|
}
|
|
101
|
+
|
|
102
|
+
// src/helpers/SeoMetaTags.tsx
|
|
103
|
+
import React from "react";
|
|
104
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
69
105
|
function SeoMetaTags({ data, baseUrl, path, defaults, imageUrlResolver }) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
106
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
107
|
+
const meta = buildSeoMeta({ seo: data, baseUrl, path, defaults, imageUrlResolver });
|
|
108
|
+
const robotsContent = [
|
|
109
|
+
((_a = meta.robots) == null ? void 0 : _a.index) === false ? "noindex" : "index",
|
|
110
|
+
((_b = meta.robots) == null ? void 0 : _b.follow) === false ? "nofollow" : "follow"
|
|
73
111
|
].join(", ");
|
|
74
|
-
return /* @__PURE__ */
|
|
75
|
-
meta.title && /* @__PURE__ */
|
|
76
|
-
meta.description && /* @__PURE__ */
|
|
77
|
-
meta.keywords
|
|
78
|
-
/* @__PURE__ */
|
|
79
|
-
/* @__PURE__ */
|
|
80
|
-
meta.openGraph
|
|
81
|
-
meta.openGraph
|
|
82
|
-
meta.openGraph
|
|
83
|
-
meta.openGraph
|
|
84
|
-
meta.openGraph
|
|
85
|
-
meta.openGraph
|
|
86
|
-
/* @__PURE__ */
|
|
87
|
-
img.width && /* @__PURE__ */
|
|
88
|
-
img.height && /* @__PURE__ */
|
|
89
|
-
img.alt && /* @__PURE__ */
|
|
112
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
113
|
+
meta.title && /* @__PURE__ */ jsx("title", { children: meta.title }),
|
|
114
|
+
meta.description && /* @__PURE__ */ jsx("meta", { name: "description", content: meta.description }),
|
|
115
|
+
((_c = meta.keywords) == null ? void 0 : _c.length) ? /* @__PURE__ */ jsx("meta", { name: "keywords", content: meta.keywords.join(", ") }) : null,
|
|
116
|
+
/* @__PURE__ */ jsx("meta", { name: "robots", content: robotsContent }),
|
|
117
|
+
/* @__PURE__ */ jsx("meta", { name: "googlebot", content: robotsContent }),
|
|
118
|
+
((_d = meta.openGraph) == null ? void 0 : _d.type) && /* @__PURE__ */ jsx("meta", { property: "og:type", content: meta.openGraph.type }),
|
|
119
|
+
((_e = meta.openGraph) == null ? void 0 : _e.url) && /* @__PURE__ */ jsx("meta", { property: "og:url", content: meta.openGraph.url }),
|
|
120
|
+
((_f = meta.openGraph) == null ? void 0 : _f.title) && /* @__PURE__ */ jsx("meta", { property: "og:title", content: meta.openGraph.title }),
|
|
121
|
+
((_g = meta.openGraph) == null ? void 0 : _g.description) && /* @__PURE__ */ jsx("meta", { property: "og:description", content: meta.openGraph.description }),
|
|
122
|
+
((_h = meta.openGraph) == null ? void 0 : _h.siteName) && /* @__PURE__ */ jsx("meta", { property: "og:site_name", content: meta.openGraph.siteName }),
|
|
123
|
+
(_j = (_i = meta.openGraph) == null ? void 0 : _i.images) == null ? void 0 : _j.map((img, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
124
|
+
/* @__PURE__ */ jsx("meta", { property: "og:image", content: img.url }),
|
|
125
|
+
img.width && /* @__PURE__ */ jsx("meta", { property: "og:image:width", content: String(img.width) }),
|
|
126
|
+
img.height && /* @__PURE__ */ jsx("meta", { property: "og:image:height", content: String(img.height) }),
|
|
127
|
+
img.alt && /* @__PURE__ */ jsx("meta", { property: "og:image:alt", content: img.alt })
|
|
90
128
|
] }, `og-img-${i}`)),
|
|
91
|
-
meta.twitter
|
|
92
|
-
meta.twitter
|
|
93
|
-
meta.twitter
|
|
94
|
-
meta.twitter
|
|
95
|
-
meta.twitter
|
|
96
|
-
meta.twitter
|
|
97
|
-
meta.other && Object.entries(meta.other).map(([name, content]) => /* @__PURE__ */
|
|
98
|
-
meta.alternates
|
|
129
|
+
((_k = meta.twitter) == null ? void 0 : _k.card) && /* @__PURE__ */ jsx("meta", { name: "twitter:card", content: meta.twitter.card }),
|
|
130
|
+
((_l = meta.twitter) == null ? void 0 : _l.site) && /* @__PURE__ */ jsx("meta", { name: "twitter:site", content: meta.twitter.site }),
|
|
131
|
+
((_m = meta.twitter) == null ? void 0 : _m.creator) && /* @__PURE__ */ jsx("meta", { name: "twitter:creator", content: meta.twitter.creator }),
|
|
132
|
+
((_n = meta.twitter) == null ? void 0 : _n.title) && /* @__PURE__ */ jsx("meta", { name: "twitter:title", content: meta.twitter.title }),
|
|
133
|
+
((_o = meta.twitter) == null ? void 0 : _o.description) && /* @__PURE__ */ jsx("meta", { name: "twitter:description", content: meta.twitter.description }),
|
|
134
|
+
(_q = (_p = meta.twitter) == null ? void 0 : _p.images) == null ? void 0 : _q.map((url, i) => /* @__PURE__ */ jsx("meta", { name: "twitter:image", content: url }, `tw-img-${i}`)),
|
|
135
|
+
meta.other && Object.entries(meta.other).map(([name, content]) => /* @__PURE__ */ jsx("meta", { name, content }, `custom-${name}`)),
|
|
136
|
+
((_r = meta.alternates) == null ? void 0 : _r.canonical) && /* @__PURE__ */ jsx("link", { rel: "canonical", href: meta.alternates.canonical })
|
|
99
137
|
] });
|
|
100
138
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
139
|
+
export {
|
|
140
|
+
SeoMetaTags,
|
|
141
|
+
buildSeoMeta,
|
|
142
|
+
sanitizeOGType,
|
|
143
|
+
sanitizeTwitterCard
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=next.js.map
|
package/dist/next.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next.js","sources":["../src/helpers/seoMeta.ts","../src/helpers/SeoMetaTags.tsx"],"sourcesContent":["/**\n * Headless CMS integration helpers for sanity-plugin-seofields\n *\n * Provides framework-agnostic SEO metadata utilities for use with:\n * - Next.js App Router → buildSeoMeta() inside generateMetadata()\n * - Next.js Pages Router → <SeoMetaTags> inside Next.js <Head>\n * - Nuxt / Remix / any SSR → <SeoMetaTags> inside your <head> slot\n */\n\nimport type {SanityImage, SanityImageWithAlt, SeoFields} from '../types'\n\n// ─── Types ────────────────────────────────────────────────────────────────────\n\n/** Structured metadata returned by buildSeoMeta(). Compatible with Next.js Metadata (App Router). */\nexport interface SeoMetadata {\n title?: string | null\n description?: string | null\n keywords?: string[]\n robots?: {\n index?: boolean\n follow?: boolean\n googleBot?: {\n index?: boolean\n follow?: boolean\n }\n }\n openGraph?: {\n type?: string\n url?: string\n title?: string\n description?: string\n siteName?: string\n images?: Array<{url: string; width?: number; height?: number; alt?: string}>\n }\n twitter?: {\n card?: string\n site?: string\n creator?: string\n title?: string\n description?: string\n images?: string[]\n }\n alternates?: {\n canonical?: string\n }\n /** Any custom meta attributes from seo.metaAttributes */\n other?: Record<string, string>\n}\n\n/** Default values used when SEO fields are missing. */\nexport interface SeoMetaDefaults {\n title?: string\n description?: string\n siteName?: string\n twitterSite?: string\n twitterCreator?: string\n /** Fallback image URL when no OG / Twitter image is set. */\n ogImage?: string\n}\n\n/**\n * Permissive image shape accepted by buildSeoMeta — compatible with both the\n * plugin's SanityImage and Sanity's code-generated image type (where `asset`\n * and `alt` are optional).\n */\ninterface SeoImageInput {\n _type?: string\n asset?: {_ref: string; _type: string; _weak?: boolean; [key: string]: unknown}\n hotspot?: unknown\n crop?: unknown\n alt?: string\n}\n\n/**\n * Input-compatible variant of SeoFields. Structurally matches Sanity's\n * code-generated types (where `asset`, `alt`, `key`, and `type` are all\n * optional), so you can pass `data.seo` from a sanityFetch result directly\n * without any `as any` or manual casting.\n */\nexport interface SeoFieldsInput {\n _type?: string\n robots?: {noIndex?: boolean | null; noFollow?: boolean | null} | null\n title?: string | null\n description?: string | null\n metaImage?: SeoImageInput | null\n metaAttributes?: Array<{_key?: string; key?: string; value?: string; type?: string}> | null\n keywords?: string[] | null\n canonicalUrl?: string | null\n openGraph?: {\n _type?: string\n url?: string | null\n title?: string | null\n description?: string | null\n siteName?: string | null\n type?: string | null\n imageType?: string | null\n image?: SeoImageInput | null\n imageUrl?: string | null\n } | null\n twitter?: {\n _type?: string\n card?: string | null\n site?: string | null\n creator?: string | null\n title?: string | null\n description?: string | null\n imageType?: string | null\n image?: SeoImageInput | null\n imageUrl?: string | null\n } | null\n}\n\n/** Options accepted by buildSeoMeta(). */\nexport interface BuildSeoMetaOptions {\n /**\n * The raw SEO object from Sanity (_type excluded or included — both work).\n * Pass `null` or `undefined` to fall back entirely to `defaults`.\n *\n * Accepts both the strict plugin `SeoFields` type and Sanity's code-generated\n * type (which has all nested fields optional) without any `as any` cast.\n */\n seo?: SeoFieldsInput | null\n\n /**\n * The base URL of your site, e.g. \"https://example.com\".\n * Used for canonical URL and OpenGraph URL construction.\n */\n baseUrl?: string\n\n /**\n * The path for the current page, e.g. \"/about\".\n * Combined with baseUrl to produce the canonical + OG url.\n * Defaults to \"\".\n */\n path?: string\n\n /**\n * Default values used when the Sanity SEO fields are empty / missing.\n */\n defaults?: SeoMetaDefaults\n\n /**\n * Resolve a Sanity image asset to a plain URL string.\n *\n * @example (using @sanity/image-url)\n * imageUrlResolver: (img) => urlFor(img).width(1200).url()\n */\n imageUrlResolver?: (image: SanityImage | SanityImageWithAlt) => string | null | undefined\n}\n\n// ─── Internal helpers ─────────────────────────────────────────────────────────\n\nconst VALID_OG_TYPES = [\n 'website',\n 'article',\n 'profile',\n 'book',\n 'music',\n 'video',\n 'product',\n] as const\ntype OGType = (typeof VALID_OG_TYPES)[number]\n\n/**\n * Coerce an arbitrary string to a valid OpenGraph type.\n * Falls back to \"website\" when the value is invalid.\n */\nexport function sanitizeOGType(value?: string): OGType {\n if (value && (VALID_OG_TYPES as readonly string[]).includes(value)) {\n return value as OGType\n }\n return 'website'\n}\n\nconst VALID_TWITTER_CARDS = ['summary', 'summary_large_image', 'app', 'player'] as const\ntype TwitterCard = (typeof VALID_TWITTER_CARDS)[number]\n\n/**\n * Coerce an arbitrary string to a valid Twitter card type.\n * Falls back to \"summary_large_image\" when the value is invalid.\n */\nexport function sanitizeTwitterCard(value?: string): TwitterCard {\n if (value && (VALID_TWITTER_CARDS as readonly string[]).includes(value)) {\n return value as TwitterCard\n }\n return 'summary_large_image'\n}\n\n// ─── Core builder ─────────────────────────────────────────────────────────────\n\n/**\n * Convert a Sanity SEO object into a structured metadata object.\n *\n * The return value is structurally compatible with Next.js App Router's\n * `Metadata` type, so you can return it directly from `generateMetadata()`.\n *\n * @example Next.js App Router\n * ```ts\n * import { buildSeoMeta } from 'sanity-plugin-seofields'\n * import { urlFor } from '@/sanity/lib/image'\n *\n * export async function generateMetadata(): Promise<Metadata> {\n * const { seo } = await sanityFetch({ query: PAGE_SEO_QUERY })\n * return buildSeoMeta({\n * seo,\n * baseUrl: process.env.NEXT_PUBLIC_SITE_URL,\n * path: '/about',\n * defaults: { title: 'My Site', siteName: 'My Site' },\n * imageUrlResolver: (img) => urlFor(img).width(1200).url(),\n * })\n * }\n * ```\n */\nexport function buildSeoMeta(options: BuildSeoMetaOptions): SeoMetadata {\n const {seo, baseUrl = '', path = '', defaults = {}, imageUrlResolver} = options\n\n const normalizedBase = baseUrl.replace(/\\/+$/, '') // remove trailing /\n const normalizedPath = path.replace(/^\\/+/, '') // remove leading /\n\n const fullUrl = [normalizedBase, normalizedPath].filter(Boolean).join('/')\n\n // ── OG image resolution ──\n let ogImageURL: string = defaults.ogImage || ''\n if (seo?.openGraph?.imageType === 'url' && seo.openGraph.imageUrl) {\n ogImageURL = seo.openGraph.imageUrl\n } else if (seo?.openGraph?.image && imageUrlResolver) {\n ogImageURL = imageUrlResolver(seo.openGraph.image as SanityImage) || ogImageURL\n }\n\n // ── Twitter image resolution ──\n let twitterImageURL: string = ogImageURL // reuse OG image as fallback\n if (seo?.twitter?.imageType === 'url' && seo.twitter.imageUrl) {\n twitterImageURL = seo.twitter.imageUrl\n } else if (seo?.twitter?.image && imageUrlResolver) {\n twitterImageURL = imageUrlResolver(seo.twitter.image as SanityImage) || twitterImageURL\n }\n\n // ── Custom meta attributes → `other` map ──\n const other: Record<string, string> = {}\n if (Array.isArray(seo?.metaAttributes)) {\n for (const attr of seo!.metaAttributes!) {\n if (attr.key && attr.value) {\n other[attr.key] = attr.value\n }\n }\n }\n\n const ogUrl = seo?.openGraph?.url || fullUrl\n\n return {\n title: seo?.title ?? defaults.title ?? null,\n description: seo?.description ?? defaults.description ?? null,\n keywords: seo?.keywords?.length ? (seo.keywords as string[]) : undefined,\n robots: {\n index: !seo?.robots?.noIndex,\n follow: !seo?.robots?.noFollow,\n googleBot: {\n index: !seo?.robots?.noIndex,\n follow: !seo?.robots?.noFollow,\n },\n },\n openGraph: {\n type: sanitizeOGType(seo?.openGraph?.type ?? undefined),\n url: ogUrl || undefined,\n title: seo?.openGraph?.title ?? defaults.title,\n description: seo?.openGraph?.description ?? defaults.description,\n siteName: seo?.openGraph?.siteName ?? defaults.siteName,\n images: ogImageURL ? [{url: ogImageURL}] : [],\n },\n twitter: {\n card: sanitizeTwitterCard(seo?.twitter?.card ?? undefined),\n site: seo?.twitter?.site ?? defaults.twitterSite,\n creator: seo?.twitter?.creator ?? defaults.twitterCreator,\n title: seo?.twitter?.title ?? defaults.title,\n description: seo?.twitter?.description ?? defaults.description,\n images: twitterImageURL ? [twitterImageURL] : [],\n },\n alternates: {\n canonical: fullUrl || undefined,\n },\n ...(Object.keys(other).length > 0 ? {other} : {}),\n }\n}\n","/**\n * <SeoMetaTags> — Framework-agnostic React SEO meta tag renderer.\n *\n * Renders all SEO meta tags as plain React elements.\n * Place it inside your framework's <Head> component:\n *\n * @example Next.js Pages Router\n * ```tsx\n * import Head from 'next/head'\n * import { SeoMetaTags } from 'sanity-plugin-seofields'\n *\n * export default function Page({ seo }) {\n * return (\n * <>\n * <Head>\n * <SeoMetaTags\n * data={seo}\n * baseUrl=\"https://example.com\"\n * path=\"/about\"\n * defaults={{ title: 'My Site', siteName: 'My Site' }}\n * imageUrlResolver={(img) => urlFor(img).width(1200).url()}\n * />\n * </Head>\n * <main>...</main>\n * </>\n * )\n * }\n * ```\n *\n * @example Nuxt 3 / generic SSR (inside <Head> slot)\n * ```tsx\n * <Head>\n * <SeoMetaTags data={seo} baseUrl=\"https://example.com\" path=\"/\" />\n * </Head>\n * ```\n */\nimport React from 'react'\n\nimport type {SanityImage, SanityImageWithAlt, SeoFields} from '../types'\nimport {buildSeoMeta, type BuildSeoMetaOptions} from './seoMeta'\n\n// ─── Props ────────────────────────────────────────────────────────────────────\n\nexport interface SeoMetaTagsProps {\n /**\n * The raw SEO object from Sanity.\n * Pass `null` / `undefined` to render only the defaults.\n */\n data?: Partial<SeoFields> | null\n\n /**\n * Base URL of your site, e.g. \"https://example.com\".\n * Used for canonical link, og:url fallback.\n */\n baseUrl?: string\n\n /**\n * Current page path, e.g. \"/about\".\n * Defaults to \"\".\n */\n path?: string\n\n /**\n * Default values used when SEO fields are missing.\n */\n defaults?: BuildSeoMetaOptions['defaults']\n\n /**\n * Resolve a Sanity image asset reference to a full URL string.\n *\n * @example\n * imageUrlResolver={(img) => urlFor(img).width(1200).url()}\n */\n imageUrlResolver?: (image: SanityImage | SanityImageWithAlt) => string | null | undefined\n}\n\n// ─── Component ────────────────────────────────────────────────────────────────\n\n/**\n * Renders all SEO meta tags for a page as plain React elements.\n * Intended to be placed inside your framework's <Head> / <head> component.\n *\n * Renders:\n * - `<title>`\n * - `<meta name=\"description\">`\n * - `<meta name=\"keywords\">`\n * - `<meta name=\"robots\">`\n * - OpenGraph meta tags (`og:*`)\n * - Twitter Card meta tags (`twitter:*`)\n * - Any custom `seo.metaAttributes` as `<meta name=\"...\" content=\"...\">`\n */\nexport function SeoMetaTags({data, baseUrl, path, defaults, imageUrlResolver}: SeoMetaTagsProps) {\n const meta = buildSeoMeta({seo: data, baseUrl, path, defaults, imageUrlResolver})\n\n const robotsContent = [\n meta.robots?.index === false ? 'noindex' : 'index',\n meta.robots?.follow === false ? 'nofollow' : 'follow',\n ].join(', ')\n\n return (\n <>\n {/* ── Title ── */}\n {meta.title && <title>{meta.title}</title>}\n\n {/* ── Basic meta ── */}\n {meta.description && <meta name=\"description\" content={meta.description} />}\n {meta.keywords?.length ? <meta name=\"keywords\" content={meta.keywords.join(', ')} /> : null}\n <meta name=\"robots\" content={robotsContent} />\n <meta name=\"googlebot\" content={robotsContent} />\n\n {/* ── Open Graph ── */}\n {meta.openGraph?.type && <meta property=\"og:type\" content={meta.openGraph.type} />}\n {meta.openGraph?.url && <meta property=\"og:url\" content={meta.openGraph.url} />}\n {meta.openGraph?.title && <meta property=\"og:title\" content={meta.openGraph.title} />}\n {meta.openGraph?.description && (\n <meta property=\"og:description\" content={meta.openGraph.description} />\n )}\n {meta.openGraph?.siteName && (\n <meta property=\"og:site_name\" content={meta.openGraph.siteName} />\n )}\n {meta.openGraph?.images?.map((img, i) => (\n <React.Fragment key={`og-img-${i}`}>\n <meta property=\"og:image\" content={img.url} />\n {img.width && <meta property=\"og:image:width\" content={String(img.width)} />}\n {img.height && <meta property=\"og:image:height\" content={String(img.height)} />}\n {img.alt && <meta property=\"og:image:alt\" content={img.alt} />}\n </React.Fragment>\n ))}\n\n {/* ── Twitter Card ── */}\n {meta.twitter?.card && <meta name=\"twitter:card\" content={meta.twitter.card} />}\n {meta.twitter?.site && <meta name=\"twitter:site\" content={meta.twitter.site} />}\n {meta.twitter?.creator && <meta name=\"twitter:creator\" content={meta.twitter.creator} />}\n {meta.twitter?.title && <meta name=\"twitter:title\" content={meta.twitter.title} />}\n {meta.twitter?.description && (\n <meta name=\"twitter:description\" content={meta.twitter.description} />\n )}\n {meta.twitter?.images?.map((url, i) => (\n <meta key={`tw-img-${i}`} name=\"twitter:image\" content={url} />\n ))}\n\n {/* ── Custom meta attributes ── */}\n {meta.other &&\n Object.entries(meta.other).map(([name, content]) => (\n <meta key={`custom-${name}`} name={name} content={content} />\n ))}\n\n {/* ── Canonical URL ── */}\n {meta.alternates?.canonical && <link rel=\"canonical\" href={meta.alternates.canonical} />}\n </>\n )\n}\n\nexport default SeoMetaTags\n"],"names":["jsxs","Fragment","jsx","React"],"mappings":";;;;;;;AAwJA,MAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAOO,SAAS,eAAe,OAAwB;AACrD,SAAI,SAAU,eAAqC,SAAS,KAAK,IACxD,QAEF;AACT;AAEA,MAAM,sBAAsB,CAAC,WA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ACD;AAAA,IAGA,KAAK,SAAS,QAAQA,2BAAAA,IAAC,QAAA,EAAK,MAAK,gBAAe,SAAS,KAAK,QAAQ,KAAA,CAAM;AAAA,IAC5E,KAAK,SAAS,QAAQA,2BAAAA,IAAC,QAAA,EAAK,MAAK,gBAAe,SAAS,KAAK,QAAQ,KAAA,CAAM;AAAA,IAC5E,KAAK,SAAS,WAAWA,2BAAAA,IAAC,QAAA,EAAK,MAAK,mBAAkB,SAAS,KAAK,QAAQ,QAAA,CAAS;AAAA,IACrF,KAAK,SAAS,SAASA,2BAAAA,IAAC,QAAA,EAAK,MAAK,iBAAgB,SAAS,KAAK,QAAQ,MAAA,CAAO;AAAA,IAC/E,KAAK,SAAS,eACbA,2BAAAA,IAAC,QAAA,EAAK,MAAK,uBAAsB,SAAS,KAAK,QAAQ,YAAA,CAAa;AAAA,IAErE,KAAK,SAAS,QAAQ,IAAI,CAAC,KAAK,MAC/BA,2BAAAA,IAAC,QAAA,EAAyB,MAAK,iBAAgB,SAAS,IAAA,GAA7C,UAAU,CAAC,EAAuC,CAC9D;AAAA,IAGA,KAAK,SACJ,OAAO,QAAQ,KAAK,KAAK,EAAE,IAAI,CAAC,CAAC,MAAM,OAAO,qCAC3C,QAAA,EAA4B,MAAY,WAA9B,UAAU,IAAI,EAAkC,CAC5D;AAAA,IAGF,KAAK,YAAY,aAAaA,2BAAAA,IAAC,QAAA,EAAK,KAAI,aAAY,MAAM,KAAK,WAAW,UAAA,CAAW;AAAA,EAAA,GACxF;AAEJ;;;;;"}
|
|
1
|
+
{"version":3,"sources":["../src/helpers/seoMeta.ts","../src/helpers/SeoMetaTags.tsx"],"sourcesContent":["/**\n * Headless CMS integration helpers for sanity-plugin-seofields\n *\n * Provides framework-agnostic SEO metadata utilities for use with:\n * - Next.js App Router → buildSeoMeta() inside generateMetadata()\n * - Next.js Pages Router → <SeoMetaTags> inside Next.js <Head>\n * - Nuxt / Remix / any SSR → <SeoMetaTags> inside your <head> slot\n */\n\nimport type {SanityImage, SanityImageWithAlt, SeoFields} from '../types'\n\n// ─── Types ────────────────────────────────────────────────────────────────────\n\n/** Structured metadata returned by buildSeoMeta(). Compatible with Next.js Metadata (App Router). */\nexport interface SeoMetadata {\n title?: string | null\n description?: string | null\n keywords?: string[]\n robots?: {\n index?: boolean\n follow?: boolean\n googleBot?: {\n index?: boolean\n follow?: boolean\n }\n }\n openGraph?: {\n type?: string\n url?: string\n title?: string\n description?: string\n siteName?: string\n images?: Array<{url: string; width?: number; height?: number; alt?: string}>\n }\n twitter?: {\n card?: string\n site?: string\n creator?: string\n title?: string\n description?: string\n images?: string[]\n }\n alternates?: {\n canonical?: string\n }\n /** Any custom meta attributes from seo.metaAttributes */\n other?: Record<string, string>\n}\n\n/** Default values used when SEO fields are missing. */\nexport interface SeoMetaDefaults {\n title?: string\n description?: string\n siteName?: string\n twitterSite?: string\n twitterCreator?: string\n /** Fallback image URL when no OG / Twitter image is set. */\n ogImage?: string\n}\n\n/**\n * Permissive image shape accepted by buildSeoMeta — compatible with both the\n * plugin's SanityImage and Sanity's code-generated image type (where `asset`\n * and `alt` are optional).\n */\ninterface SeoImageInput {\n _type?: string\n asset?: {_ref: string; _type: string; _weak?: boolean; [key: string]: unknown}\n hotspot?: unknown\n crop?: unknown\n alt?: string\n}\n\n/**\n * Input-compatible variant of SeoFields. Structurally matches Sanity's\n * code-generated types (where `asset`, `alt`, `key`, and `type` are all\n * optional), so you can pass `data.seo` from a sanityFetch result directly\n * without any `as any` or manual casting.\n */\nexport interface SeoFieldsInput {\n _type?: string\n robots?: {noIndex?: boolean | null; noFollow?: boolean | null} | null\n title?: string | null\n description?: string | null\n metaImage?: SeoImageInput | null\n metaAttributes?: Array<{_key?: string; key?: string; value?: string; type?: string}> | null\n keywords?: string[] | null\n canonicalUrl?: string | null\n openGraph?: {\n _type?: string\n url?: string | null\n title?: string | null\n description?: string | null\n siteName?: string | null\n type?: string | null\n imageType?: string | null\n image?: SeoImageInput | null\n imageUrl?: string | null\n } | null\n twitter?: {\n _type?: string\n card?: string | null\n site?: string | null\n creator?: string | null\n title?: string | null\n description?: string | null\n imageType?: string | null\n image?: SeoImageInput | null\n imageUrl?: string | null\n } | null\n}\n\n/** Options accepted by buildSeoMeta(). */\nexport interface BuildSeoMetaOptions {\n /**\n * The raw SEO object from Sanity (_type excluded or included — both work).\n * Pass `null` or `undefined` to fall back entirely to `defaults`.\n *\n * Accepts both the strict plugin `SeoFields` type and Sanity's code-generated\n * type (which has all nested fields optional) without any `as any` cast.\n */\n seo?: SeoFieldsInput | null\n\n /**\n * The base URL of your site, e.g. \"https://example.com\".\n * Used for canonical URL and OpenGraph URL construction.\n */\n baseUrl?: string\n\n /**\n * The path for the current page, e.g. \"/about\".\n * Combined with baseUrl to produce the canonical + OG url.\n * Defaults to \"\".\n */\n path?: string\n\n /**\n * Default values used when the Sanity SEO fields are empty / missing.\n */\n defaults?: SeoMetaDefaults\n\n /**\n * Resolve a Sanity image asset to a plain URL string.\n *\n * @example (using @sanity/image-url)\n * imageUrlResolver: (img) => urlFor(img).width(1200).url()\n */\n imageUrlResolver?: (image: SanityImage | SanityImageWithAlt) => string | null | undefined\n}\n\n// ─── Internal helpers ─────────────────────────────────────────────────────────\n\nconst VALID_OG_TYPES = [\n 'website',\n 'article',\n 'profile',\n 'book',\n 'music',\n 'video',\n 'product',\n] as const\ntype OGType = (typeof VALID_OG_TYPES)[number]\n\n/**\n * Coerce an arbitrary string to a valid OpenGraph type.\n * Falls back to \"website\" when the value is invalid.\n */\nexport function sanitizeOGType(value?: string): OGType {\n if (value && (VALID_OG_TYPES as readonly string[]).includes(value)) {\n return value as OGType\n }\n return 'website'\n}\n\nconst VALID_TWITTER_CARDS = ['summary', 'summary_large_image', 'app', 'player'] as const\ntype TwitterCard = (typeof VALID_TWITTER_CARDS)[number]\n\n/**\n * Coerce an arbitrary string to a valid Twitter card type.\n * Falls back to \"summary_large_image\" when the value is invalid.\n */\nexport function sanitizeTwitterCard(value?: string): TwitterCard {\n if (value && (VALID_TWITTER_CARDS as readonly string[]).includes(value)) {\n return value as TwitterCard\n }\n return 'summary_large_image'\n}\n\n// ─── Core builder ─────────────────────────────────────────────────────────────\n\n/**\n * Convert a Sanity SEO object into a structured metadata object.\n *\n * The return value is structurally compatible with Next.js App Router's\n * `Metadata` type, so you can return it directly from `generateMetadata()`.\n *\n * @example Next.js App Router\n * ```ts\n * import { buildSeoMeta } from 'sanity-plugin-seofields'\n * import { urlFor } from '@/sanity/lib/image'\n *\n * export async function generateMetadata(): Promise<Metadata> {\n * const { seo } = await sanityFetch({ query: PAGE_SEO_QUERY })\n * return buildSeoMeta({\n * seo,\n * baseUrl: process.env.NEXT_PUBLIC_SITE_URL,\n * path: '/about',\n * defaults: { title: 'My Site', siteName: 'My Site' },\n * imageUrlResolver: (img) => urlFor(img).width(1200).url(),\n * })\n * }\n * ```\n */\nexport function buildSeoMeta(options: BuildSeoMetaOptions): SeoMetadata {\n const {seo, baseUrl = '', path = '', defaults = {}, imageUrlResolver} = options\n\n const normalizedBase = baseUrl.replace(/\\/+$/, '') // remove trailing /\n const normalizedPath = path.replace(/^\\/+/, '') // remove leading /\n\n const fullUrl = [normalizedBase, normalizedPath].filter(Boolean).join('/')\n\n // ── OG image resolution ──\n let ogImageURL: string = defaults.ogImage || ''\n if (seo?.openGraph?.imageType === 'url' && seo.openGraph.imageUrl) {\n ogImageURL = seo.openGraph.imageUrl\n } else if (seo?.openGraph?.image && imageUrlResolver) {\n ogImageURL = imageUrlResolver(seo.openGraph.image as SanityImage) || ogImageURL\n }\n\n // ── Twitter image resolution ──\n let twitterImageURL: string = ogImageURL // reuse OG image as fallback\n if (seo?.twitter?.imageType === 'url' && seo.twitter.imageUrl) {\n twitterImageURL = seo.twitter.imageUrl\n } else if (seo?.twitter?.image && imageUrlResolver) {\n twitterImageURL = imageUrlResolver(seo.twitter.image as SanityImage) || twitterImageURL\n }\n\n // ── Custom meta attributes → `other` map ──\n const other: Record<string, string> = {}\n if (Array.isArray(seo?.metaAttributes)) {\n for (const attr of seo!.metaAttributes!) {\n if (attr.key && attr.value) {\n other[attr.key] = attr.value\n }\n }\n }\n\n const ogUrl = seo?.openGraph?.url || fullUrl\n\n return {\n title: seo?.title ?? defaults.title ?? null,\n description: seo?.description ?? defaults.description ?? null,\n keywords: seo?.keywords?.length ? (seo.keywords as string[]) : undefined,\n robots: {\n index: !seo?.robots?.noIndex,\n follow: !seo?.robots?.noFollow,\n googleBot: {\n index: !seo?.robots?.noIndex,\n follow: !seo?.robots?.noFollow,\n },\n },\n openGraph: {\n type: sanitizeOGType(seo?.openGraph?.type ?? undefined),\n url: ogUrl || undefined,\n title: seo?.openGraph?.title ?? defaults.title,\n description: seo?.openGraph?.description ?? defaults.description,\n siteName: seo?.openGraph?.siteName ?? defaults.siteName,\n images: ogImageURL ? [{url: ogImageURL}] : [],\n },\n twitter: {\n card: sanitizeTwitterCard(seo?.twitter?.card ?? undefined),\n site: seo?.twitter?.site ?? defaults.twitterSite,\n creator: seo?.twitter?.creator ?? defaults.twitterCreator,\n title: seo?.twitter?.title ?? defaults.title,\n description: seo?.twitter?.description ?? defaults.description,\n images: twitterImageURL ? [twitterImageURL] : [],\n },\n alternates: {\n canonical: fullUrl || undefined,\n },\n ...(Object.keys(other).length > 0 ? {other} : {}),\n }\n}\n","/**\n * <SeoMetaTags> — Framework-agnostic React SEO meta tag renderer.\n *\n * Renders all SEO meta tags as plain React elements.\n * Place it inside your framework's <Head> component:\n *\n * @example Next.js Pages Router\n * ```tsx\n * import Head from 'next/head'\n * import { SeoMetaTags } from 'sanity-plugin-seofields'\n *\n * export default function Page({ seo }) {\n * return (\n * <>\n * <Head>\n * <SeoMetaTags\n * data={seo}\n * baseUrl=\"https://example.com\"\n * path=\"/about\"\n * defaults={{ title: 'My Site', siteName: 'My Site' }}\n * imageUrlResolver={(img) => urlFor(img).width(1200).url()}\n * />\n * </Head>\n * <main>...</main>\n * </>\n * )\n * }\n * ```\n *\n * @example Nuxt 3 / generic SSR (inside <Head> slot)\n * ```tsx\n * <Head>\n * <SeoMetaTags data={seo} baseUrl=\"https://example.com\" path=\"/\" />\n * </Head>\n * ```\n */\nimport React from 'react'\n\nimport type {SanityImage, SanityImageWithAlt, SeoFields} from '../types'\nimport {buildSeoMeta, type BuildSeoMetaOptions} from './seoMeta'\n\n// ─── Props ────────────────────────────────────────────────────────────────────\n\nexport interface SeoMetaTagsProps {\n /**\n * The raw SEO object from Sanity.\n * Pass `null` / `undefined` to render only the defaults.\n */\n data?: Partial<SeoFields> | null\n\n /**\n * Base URL of your site, e.g. \"https://example.com\".\n * Used for canonical link, og:url fallback.\n */\n baseUrl?: string\n\n /**\n * Current page path, e.g. \"/about\".\n * Defaults to \"\".\n */\n path?: string\n\n /**\n * Default values used when SEO fields are missing.\n */\n defaults?: BuildSeoMetaOptions['defaults']\n\n /**\n * Resolve a Sanity image asset reference to a full URL string.\n *\n * @example\n * imageUrlResolver={(img) => urlFor(img).width(1200).url()}\n */\n imageUrlResolver?: (image: SanityImage | SanityImageWithAlt) => string | null | undefined\n}\n\n// ─── Component ────────────────────────────────────────────────────────────────\n\n/**\n * Renders all SEO meta tags for a page as plain React elements.\n * Intended to be placed inside your framework's <Head> / <head> component.\n *\n * Renders:\n * - `<title>`\n * - `<meta name=\"description\">`\n * - `<meta name=\"keywords\">`\n * - `<meta name=\"robots\">`\n * - OpenGraph meta tags (`og:*`)\n * - Twitter Card meta tags (`twitter:*`)\n * - Any custom `seo.metaAttributes` as `<meta name=\"...\" content=\"...\">`\n */\nexport function SeoMetaTags({data, baseUrl, path, defaults, imageUrlResolver}: SeoMetaTagsProps) {\n const meta = buildSeoMeta({seo: data, baseUrl, path, defaults, imageUrlResolver})\n\n const robotsContent = [\n meta.robots?.index === false ? 'noindex' : 'index',\n meta.robots?.follow === false ? 'nofollow' : 'follow',\n ].join(', ')\n\n return (\n <>\n {/* ── Title ── */}\n {meta.title && <title>{meta.title}</title>}\n\n {/* ── Basic meta ── */}\n {meta.description && <meta name=\"description\" content={meta.description} />}\n {meta.keywords?.length ? <meta name=\"keywords\" content={meta.keywords.join(', ')} /> : null}\n <meta name=\"robots\" content={robotsContent} />\n <meta name=\"googlebot\" content={robotsContent} />\n\n {/* ── Open Graph ── */}\n {meta.openGraph?.type && <meta property=\"og:type\" content={meta.openGraph.type} />}\n {meta.openGraph?.url && <meta property=\"og:url\" content={meta.openGraph.url} />}\n {meta.openGraph?.title && <meta property=\"og:title\" content={meta.openGraph.title} />}\n {meta.openGraph?.description && (\n <meta property=\"og:description\" content={meta.openGraph.description} />\n )}\n {meta.openGraph?.siteName && (\n <meta property=\"og:site_name\" content={meta.openGraph.siteName} />\n )}\n {meta.openGraph?.images?.map((img, i) => (\n <React.Fragment key={`og-img-${i}`}>\n <meta property=\"og:image\" content={img.url} />\n {img.width && <meta property=\"og:image:width\" content={String(img.width)} />}\n {img.height && <meta property=\"og:image:height\" content={String(img.height)} />}\n {img.alt && <meta property=\"og:image:alt\" content={img.alt} />}\n </React.Fragment>\n ))}\n\n {/* ── Twitter Card ── */}\n {meta.twitter?.card && <meta name=\"twitter:card\" content={meta.twitter.card} />}\n {meta.twitter?.site && <meta name=\"twitter:site\" content={meta.twitter.site} />}\n {meta.twitter?.creator && <meta name=\"twitter:creator\" content={meta.twitter.creator} />}\n {meta.twitter?.title && <meta name=\"twitter:title\" content={meta.twitter.title} />}\n {meta.twitter?.description && (\n <meta name=\"twitter:description\" content={meta.twitter.description} />\n )}\n {meta.twitter?.images?.map((url, i) => (\n <meta key={`tw-img-${i}`} name=\"twitter:image\" content={url} />\n ))}\n\n {/* ── Custom meta attributes ── */}\n {meta.other &&\n Object.entries(meta.other).map(([name, content]) => (\n <meta key={`custom-${name}`} name={name} content={content} />\n ))}\n\n {/* ── Canonical URL ── */}\n {meta.alternates?.canonical && <link rel=\"canonical\" href={meta.alternates.canonical} />}\n </>\n )\n}\n\nexport default SeoMetaTags\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwJA,IAAM,iBAAiB;AAAA,EACrB;AA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,EAAkC,CAC5D;AAAA,MAGF,UAAK,eAAL,mBAAiB,cAAa,oBAAC,UAAK,KAAI,aAAY,MAAM,KAAK,WAAW,WAAW;AAAA,KACxF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
interface SanityImage {
|
|
2
|
+
_type: 'image';
|
|
3
|
+
asset: {
|
|
4
|
+
_ref: string;
|
|
5
|
+
_type: 'reference';
|
|
6
|
+
};
|
|
7
|
+
hotspot?: {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
height: number;
|
|
11
|
+
width: number;
|
|
12
|
+
};
|
|
13
|
+
crop?: {
|
|
14
|
+
top: number;
|
|
15
|
+
bottom: number;
|
|
16
|
+
left: number;
|
|
17
|
+
right: number;
|
|
18
|
+
};
|
|
19
|
+
alt?: string;
|
|
20
|
+
}
|
|
21
|
+
interface SanityImageWithAlt extends SanityImage {
|
|
22
|
+
alt: string;
|
|
23
|
+
}
|
|
24
|
+
interface RobotsSettings {
|
|
25
|
+
noIndex?: boolean;
|
|
26
|
+
noFollow?: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface MetaAttribute {
|
|
29
|
+
_type: 'metaAttribute';
|
|
30
|
+
key?: string;
|
|
31
|
+
type?: 'string' | 'image';
|
|
32
|
+
value?: string;
|
|
33
|
+
image?: SanityImage;
|
|
34
|
+
}
|
|
35
|
+
interface OpenGraphSettings {
|
|
36
|
+
_type: 'openGraph';
|
|
37
|
+
/** The canonical URL for OpenGraph (og:url). Maps to the `url` field in Sanity. */
|
|
38
|
+
url?: string;
|
|
39
|
+
title?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
siteName?: string;
|
|
42
|
+
type?: 'website' | 'article' | 'profile' | 'book' | 'music' | 'video' | 'product';
|
|
43
|
+
imageType?: 'upload' | 'url';
|
|
44
|
+
image?: SanityImageWithAlt;
|
|
45
|
+
imageUrl?: string;
|
|
46
|
+
}
|
|
47
|
+
interface TwitterCardSettings {
|
|
48
|
+
_type: 'twitter';
|
|
49
|
+
card?: 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
50
|
+
site?: string;
|
|
51
|
+
creator?: string;
|
|
52
|
+
title?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
imageType?: 'upload' | 'url';
|
|
55
|
+
image?: SanityImageWithAlt;
|
|
56
|
+
imageUrl?: string;
|
|
57
|
+
}
|
|
58
|
+
interface SeoFields {
|
|
59
|
+
_type: 'seoFields';
|
|
60
|
+
robots?: RobotsSettings;
|
|
61
|
+
preview?: string;
|
|
62
|
+
title?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
metaImage?: SanityImage;
|
|
65
|
+
metaAttributes?: MetaAttribute[];
|
|
66
|
+
keywords?: string[];
|
|
67
|
+
canonicalUrl?: string;
|
|
68
|
+
openGraph?: OpenGraphSettings;
|
|
69
|
+
twitter?: TwitterCardSettings;
|
|
70
|
+
}
|
|
71
|
+
type SeoHealthStatus = 'excellent' | 'good' | 'fair' | 'poor' | 'missing';
|
|
72
|
+
interface SeoHealthMetrics {
|
|
73
|
+
score: number;
|
|
74
|
+
status: SeoHealthStatus;
|
|
75
|
+
issues: string[];
|
|
76
|
+
}
|
|
77
|
+
interface DocumentWithSeoHealth {
|
|
78
|
+
_id: string;
|
|
79
|
+
_type: string;
|
|
80
|
+
title?: string;
|
|
81
|
+
slug?: {
|
|
82
|
+
current: string;
|
|
83
|
+
};
|
|
84
|
+
seo?: SeoFields;
|
|
85
|
+
_updatedAt?: string;
|
|
86
|
+
health: SeoHealthMetrics;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type { DocumentWithSeoHealth as D, SeoHealthMetrics as S, SeoHealthStatus as a, SanityImage as b, SanityImageWithAlt as c, SeoFields as d };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
interface SanityImage {
|
|
2
|
+
_type: 'image';
|
|
3
|
+
asset: {
|
|
4
|
+
_ref: string;
|
|
5
|
+
_type: 'reference';
|
|
6
|
+
};
|
|
7
|
+
hotspot?: {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
height: number;
|
|
11
|
+
width: number;
|
|
12
|
+
};
|
|
13
|
+
crop?: {
|
|
14
|
+
top: number;
|
|
15
|
+
bottom: number;
|
|
16
|
+
left: number;
|
|
17
|
+
right: number;
|
|
18
|
+
};
|
|
19
|
+
alt?: string;
|
|
20
|
+
}
|
|
21
|
+
interface SanityImageWithAlt extends SanityImage {
|
|
22
|
+
alt: string;
|
|
23
|
+
}
|
|
24
|
+
interface RobotsSettings {
|
|
25
|
+
noIndex?: boolean;
|
|
26
|
+
noFollow?: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface MetaAttribute {
|
|
29
|
+
_type: 'metaAttribute';
|
|
30
|
+
key?: string;
|
|
31
|
+
type?: 'string' | 'image';
|
|
32
|
+
value?: string;
|
|
33
|
+
image?: SanityImage;
|
|
34
|
+
}
|
|
35
|
+
interface OpenGraphSettings {
|
|
36
|
+
_type: 'openGraph';
|
|
37
|
+
/** The canonical URL for OpenGraph (og:url). Maps to the `url` field in Sanity. */
|
|
38
|
+
url?: string;
|
|
39
|
+
title?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
siteName?: string;
|
|
42
|
+
type?: 'website' | 'article' | 'profile' | 'book' | 'music' | 'video' | 'product';
|
|
43
|
+
imageType?: 'upload' | 'url';
|
|
44
|
+
image?: SanityImageWithAlt;
|
|
45
|
+
imageUrl?: string;
|
|
46
|
+
}
|
|
47
|
+
interface TwitterCardSettings {
|
|
48
|
+
_type: 'twitter';
|
|
49
|
+
card?: 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
50
|
+
site?: string;
|
|
51
|
+
creator?: string;
|
|
52
|
+
title?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
imageType?: 'upload' | 'url';
|
|
55
|
+
image?: SanityImageWithAlt;
|
|
56
|
+
imageUrl?: string;
|
|
57
|
+
}
|
|
58
|
+
interface SeoFields {
|
|
59
|
+
_type: 'seoFields';
|
|
60
|
+
robots?: RobotsSettings;
|
|
61
|
+
preview?: string;
|
|
62
|
+
title?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
metaImage?: SanityImage;
|
|
65
|
+
metaAttributes?: MetaAttribute[];
|
|
66
|
+
keywords?: string[];
|
|
67
|
+
canonicalUrl?: string;
|
|
68
|
+
openGraph?: OpenGraphSettings;
|
|
69
|
+
twitter?: TwitterCardSettings;
|
|
70
|
+
}
|
|
71
|
+
type SeoHealthStatus = 'excellent' | 'good' | 'fair' | 'poor' | 'missing';
|
|
72
|
+
interface SeoHealthMetrics {
|
|
73
|
+
score: number;
|
|
74
|
+
status: SeoHealthStatus;
|
|
75
|
+
issues: string[];
|
|
76
|
+
}
|
|
77
|
+
interface DocumentWithSeoHealth {
|
|
78
|
+
_id: string;
|
|
79
|
+
_type: string;
|
|
80
|
+
title?: string;
|
|
81
|
+
slug?: {
|
|
82
|
+
current: string;
|
|
83
|
+
};
|
|
84
|
+
seo?: SeoFields;
|
|
85
|
+
_updatedAt?: string;
|
|
86
|
+
health: SeoHealthMetrics;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type { DocumentWithSeoHealth as D, SeoHealthMetrics as S, SeoHealthStatus as a, SanityImage as b, SanityImageWithAlt as c, SeoFields as d };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-seofields",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "A Sanity Studio plugin to manage SEO fields like meta titles, descriptions, and Open Graph tags for structured, search-optimized content.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -15,38 +15,57 @@
|
|
|
15
15
|
],
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"author": "Desai Hardik <dhardik1430@gmail.com>",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./dist/index.cjs",
|
|
20
|
+
"module": "./dist/index.js",
|
|
20
21
|
"exports": {
|
|
21
22
|
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
22
24
|
"source": "./src/index.ts",
|
|
23
|
-
"import": "./dist/index.
|
|
24
|
-
"
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"require": "./dist/index.cjs"
|
|
25
27
|
},
|
|
26
28
|
"./next": {
|
|
29
|
+
"types": "./dist/next.d.ts",
|
|
27
30
|
"source": "./src/next.ts",
|
|
28
|
-
"import": "./dist/next.
|
|
29
|
-
"require": "./dist/next.
|
|
30
|
-
"default": "./dist/next.js"
|
|
31
|
+
"import": "./dist/next.js",
|
|
32
|
+
"require": "./dist/next.cjs"
|
|
31
33
|
},
|
|
32
34
|
"./package.json": "./package.json"
|
|
33
35
|
},
|
|
34
|
-
"main": "./dist/index.js",
|
|
35
36
|
"types": "./dist/index.d.ts",
|
|
37
|
+
"typesVersions": {
|
|
38
|
+
"*": {
|
|
39
|
+
"next": [
|
|
40
|
+
"./dist/next.d.ts"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": false,
|
|
36
45
|
"files": [
|
|
37
|
-
"dist"
|
|
38
|
-
"sanity.json",
|
|
39
|
-
"src",
|
|
40
|
-
"v2-incompatible.js"
|
|
46
|
+
"dist"
|
|
41
47
|
],
|
|
42
48
|
"scripts": {
|
|
43
|
-
"build": "
|
|
44
|
-
"
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"watch": "tsup --watch",
|
|
45
51
|
"link-watch": "plugin-kit link-watch",
|
|
52
|
+
"format": "prettier --write --cache --ignore-unknown .",
|
|
46
53
|
"lint": "eslint .",
|
|
47
54
|
"prepublishOnly": "npm run build",
|
|
48
55
|
"generate-schema": "npx tsx schema-generator.ts",
|
|
49
|
-
"
|
|
56
|
+
"typecheck": "tsc --noEmit"
|
|
57
|
+
},
|
|
58
|
+
"sanityPlugin": {
|
|
59
|
+
"linkWatch": {
|
|
60
|
+
"command": "pnpm run watch"
|
|
61
|
+
},
|
|
62
|
+
"verifyPackage": {
|
|
63
|
+
"pkg-utils": false,
|
|
64
|
+
"scripts": false,
|
|
65
|
+
"tsconfig": false,
|
|
66
|
+
"sanityV2Json": false,
|
|
67
|
+
"eslintImports": false
|
|
68
|
+
}
|
|
50
69
|
},
|
|
51
70
|
"dependencies": {
|
|
52
71
|
"@sanity/incompatible-plugin": "^1.0.5",
|
|
@@ -58,8 +77,7 @@
|
|
|
58
77
|
},
|
|
59
78
|
"devDependencies": {
|
|
60
79
|
"@sanity/codegen": "^4.9.0",
|
|
61
|
-
"@sanity/
|
|
62
|
-
"@sanity/plugin-kit": "^4.0.19",
|
|
80
|
+
"@sanity/plugin-kit": "^4.0.20",
|
|
63
81
|
"@types/react": "^19.1.13",
|
|
64
82
|
"@typescript-eslint/eslint-plugin": "^8.44.0",
|
|
65
83
|
"@typescript-eslint/parser": "^8.44.0",
|
|
@@ -77,6 +95,7 @@
|
|
|
77
95
|
"sanity": "^4.10.0",
|
|
78
96
|
"styled-components": "^6.1.19",
|
|
79
97
|
"ts-json-schema-generator": "^2.4.0",
|
|
98
|
+
"tsup": "^8.0.0",
|
|
80
99
|
"tsx": "^4.20.5",
|
|
81
100
|
"typescript": "^5.9.2"
|
|
82
101
|
},
|