@umituz/web-seo 2.0.21 → 2.1.1

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.
Files changed (106) hide show
  1. package/dist/domains/seo/components/JsonLd.d.ts +1 -9
  2. package/dist/domains/seo/components/JsonLd.js +22 -80
  3. package/dist/domains/seo/components/SEO.js +5 -35
  4. package/dist/domains/seo/components/index.d.ts +0 -5
  5. package/dist/domains/seo/components/index.js +0 -5
  6. package/dist/domains/seo/core/constants.d.ts +9 -0
  7. package/dist/domains/seo/core/constants.js +9 -0
  8. package/dist/domains/seo/core/deep-equal.d.ts +1 -0
  9. package/dist/domains/seo/core/deep-equal.js +21 -0
  10. package/dist/domains/seo/core/dom-queue.d.ts +3 -0
  11. package/dist/domains/seo/core/dom-queue.js +27 -0
  12. package/dist/domains/seo/core/escape.d.ts +2 -0
  13. package/dist/domains/seo/core/escape.js +31 -0
  14. package/dist/domains/seo/core/hash.d.ts +1 -0
  15. package/dist/domains/seo/core/hash.js +21 -0
  16. package/dist/domains/seo/core/init.d.ts +4 -2
  17. package/dist/domains/seo/core/init.js +27 -18
  18. package/dist/domains/seo/core/seo-strategies.d.ts +19 -0
  19. package/dist/domains/seo/core/seo-strategies.js +620 -0
  20. package/dist/domains/seo/core/seo-strategy.d.ts +16 -0
  21. package/dist/domains/seo/core/seo-strategy.js +1 -0
  22. package/dist/domains/seo/hooks/index.d.ts +0 -5
  23. package/dist/domains/seo/hooks/index.js +0 -5
  24. package/dist/domains/seo/hooks/useJsonLd.d.ts +2 -10
  25. package/dist/domains/seo/hooks/useJsonLd.js +23 -64
  26. package/dist/domains/seo/hooks/useSEO.js +2 -30
  27. package/dist/domains/seo/ssr/helmet.d.ts +18 -0
  28. package/dist/domains/seo/ssr/helmet.js +16 -0
  29. package/dist/domains/seo/ssr/index.d.ts +5 -0
  30. package/dist/domains/seo/ssr/index.js +3 -0
  31. package/dist/domains/seo/ssr/renderer.d.ts +1 -47
  32. package/dist/domains/seo/ssr/renderer.js +41 -296
  33. package/dist/domains/seo/ssr/serializer.d.ts +0 -66
  34. package/dist/domains/seo/ssr/serializer.js +21 -172
  35. package/dist/domains/seo/types/index.d.ts +0 -4
  36. package/dist/domains/seo/types/schema.d.ts +22 -3
  37. package/dist/domains/seo/types/schema.js +0 -3
  38. package/dist/domains/seo/utils/dom/dom-context.d.ts +2 -0
  39. package/dist/domains/seo/utils/dom/dom-context.js +48 -0
  40. package/dist/domains/seo/utils/dom/dom-mutator.d.ts +9 -0
  41. package/dist/domains/seo/utils/dom/dom-mutator.js +64 -0
  42. package/dist/domains/seo/utils/dom/index.d.ts +1 -0
  43. package/dist/domains/seo/utils/dom/index.js +1 -0
  44. package/dist/domains/seo/utils/index.d.ts +2 -8
  45. package/dist/domains/seo/utils/index.js +2 -12
  46. package/dist/domains/seo/utils/schema-generators/base.d.ts +14 -0
  47. package/dist/domains/seo/utils/schema-generators/base.js +39 -0
  48. package/dist/domains/seo/utils/schema-generators/factory.d.ts +20 -0
  49. package/dist/domains/seo/utils/schema-generators/factory.js +42 -0
  50. package/dist/domains/seo/utils/schema-generators/generators/article.d.ts +4 -0
  51. package/dist/domains/seo/utils/schema-generators/generators/article.js +39 -0
  52. package/dist/domains/seo/utils/schema-generators/generators/breadcrumb.d.ts +6 -0
  53. package/dist/domains/seo/utils/schema-generators/generators/breadcrumb.js +18 -0
  54. package/dist/domains/seo/utils/schema-generators/generators/course.d.ts +3 -0
  55. package/dist/domains/seo/utils/schema-generators/generators/course.js +70 -0
  56. package/dist/domains/seo/utils/schema-generators/generators/faq.d.ts +3 -0
  57. package/dist/domains/seo/utils/schema-generators/generators/faq.js +21 -0
  58. package/dist/domains/seo/utils/schema-generators/generators/local-business.d.ts +3 -0
  59. package/dist/domains/seo/utils/schema-generators/generators/local-business.js +45 -0
  60. package/dist/domains/seo/utils/schema-generators/generators/organization.d.ts +3 -0
  61. package/dist/domains/seo/utils/schema-generators/generators/organization.js +25 -0
  62. package/dist/domains/seo/utils/schema-generators/generators/person.d.ts +3 -0
  63. package/dist/domains/seo/utils/schema-generators/generators/person.js +27 -0
  64. package/dist/domains/seo/utils/schema-generators/generators/product.d.ts +3 -0
  65. package/dist/domains/seo/utils/schema-generators/generators/product.js +40 -0
  66. package/dist/domains/seo/utils/schema-generators/generators/video.d.ts +3 -0
  67. package/dist/domains/seo/utils/schema-generators/generators/video.js +23 -0
  68. package/dist/domains/seo/utils/schema-generators/generators/website.d.ts +3 -0
  69. package/dist/domains/seo/utils/schema-generators/generators/website.js +30 -0
  70. package/dist/domains/seo/utils/schema-generators/index.d.ts +13 -6
  71. package/dist/domains/seo/utils/schema-generators/index.js +11 -6
  72. package/dist/domains/seo/utils/schema-generators/types.d.ts +138 -0
  73. package/dist/domains/seo/utils/schema-generators/types.js +1 -0
  74. package/dist/domains/seo/utils/validation/hreflang-validator.d.ts +4 -0
  75. package/dist/domains/seo/utils/validation/hreflang-validator.js +10 -0
  76. package/dist/domains/seo/utils/validation/image-validator.d.ts +1 -0
  77. package/dist/domains/seo/utils/validation/image-validator.js +18 -0
  78. package/dist/domains/seo/utils/validation/index.d.ts +8 -6
  79. package/dist/domains/seo/utils/validation/index.js +8 -6
  80. package/dist/domains/seo/utils/validation/jsonld-validator.d.ts +2 -0
  81. package/dist/domains/seo/utils/validation/jsonld-validator.js +67 -0
  82. package/dist/domains/seo/utils/validation/language-code.d.ts +1 -0
  83. package/dist/domains/seo/utils/validation/language-code.js +2 -0
  84. package/dist/domains/seo/utils/validation/length-validator.d.ts +4 -0
  85. package/dist/domains/seo/utils/validation/length-validator.js +34 -0
  86. package/dist/domains/seo/utils/validation/seo-auditor.d.ts +3 -0
  87. package/dist/domains/seo/utils/validation/seo-auditor.js +120 -0
  88. package/dist/domains/seo/utils/validation/text-helpers.d.ts +1 -0
  89. package/dist/domains/seo/utils/validation/text-helpers.js +6 -0
  90. package/dist/domains/seo/utils/validation/url-validator.d.ts +2 -0
  91. package/dist/domains/seo/utils/validation/url-validator.js +20 -0
  92. package/dist/domains/seo/vite/index.d.ts +3 -7
  93. package/dist/domains/seo/vite/index.js +2 -6
  94. package/dist/domains/seo/vite/plugin.d.ts +1 -59
  95. package/dist/domains/seo/vite/plugin.js +26 -190
  96. package/dist/domains/seo/vite/presets.d.ts +8 -0
  97. package/dist/domains/seo/vite/presets.js +28 -0
  98. package/dist/domains/seo/vite/robots-generator.d.ts +6 -0
  99. package/dist/domains/seo/vite/robots-generator.js +33 -0
  100. package/dist/domains/seo/vite/sitemap-generator.d.ts +8 -0
  101. package/dist/domains/seo/vite/sitemap-generator.js +49 -0
  102. package/dist/domains/seo/vite/types.d.ts +20 -0
  103. package/dist/domains/seo/vite/types.js +1 -0
  104. package/dist/index.d.ts +8 -7
  105. package/dist/index.js +4 -12
  106. package/package.json +1 -1
@@ -0,0 +1,620 @@
1
+ import { escapeHTML, escapeJSONForScript } from "./escape.js";
2
+ const ATTR = {
3
+ rel: "rel",
4
+ href: "href",
5
+ type: "type",
6
+ sizes: "sizes",
7
+ media: "media",
8
+ as: "as",
9
+ crossorigin: "crossorigin",
10
+ hreflang: "hreflang",
11
+ color: "color",
12
+ };
13
+ const robotsDirectivesToMeta = (directives) => {
14
+ const meta = {};
15
+ for (const directive of directives) {
16
+ switch (directive) {
17
+ case "index":
18
+ meta.index = true;
19
+ break;
20
+ case "noindex":
21
+ meta.index = false;
22
+ break;
23
+ case "follow":
24
+ meta.follow = true;
25
+ break;
26
+ case "nofollow":
27
+ meta.follow = false;
28
+ break;
29
+ case "noarchive":
30
+ meta.archive = false;
31
+ break;
32
+ case "nosnippet":
33
+ meta.snippet = false;
34
+ break;
35
+ case "notranslate":
36
+ meta.translate = false;
37
+ break;
38
+ case "noimageindex":
39
+ meta.imageIndex = false;
40
+ break;
41
+ }
42
+ }
43
+ return meta;
44
+ };
45
+ const robotsMetaToString = (robots) => {
46
+ if (Array.isArray(robots)) {
47
+ return robots.join(", ");
48
+ }
49
+ const directives = [];
50
+ const push = (cond, yes, no) => {
51
+ if (cond === undefined)
52
+ return;
53
+ directives.push(cond ? yes : no);
54
+ };
55
+ push(robots.index, "index", "noindex");
56
+ push(robots.follow, "follow", "nofollow");
57
+ push(robots.archive, "all", "noarchive");
58
+ push(robots.snippet, "all", "nosnippet");
59
+ push(robots.translate, "all", "notranslate");
60
+ push(robots.imageIndex, "all", "noimageindex");
61
+ if (robots.maxSnippet !== undefined)
62
+ directives.push(`max-snippet:${robots.maxSnippet}`);
63
+ if (robots.maxImagePreview !== undefined)
64
+ directives.push(`max-image-preview:${robots.maxImagePreview}`);
65
+ if (robots.maxVideoPreview !== undefined)
66
+ directives.push(`max-video-preview:${robots.maxVideoPreview}`);
67
+ if (robots.unavailableAfter !== undefined)
68
+ directives.push(`unavailable_after:${robots.unavailableAfter}`);
69
+ return directives.join(", ");
70
+ };
71
+ export const titleStrategy = {
72
+ id: "title",
73
+ applies: (o) => Boolean(o.title || o.titleTemplate),
74
+ applyDOM: (o) => {
75
+ const value = o.titleTemplate ? o.titleTemplate.replace("%s", o.title ?? "") : o.title;
76
+ if (value)
77
+ document.title = value;
78
+ },
79
+ applyHTML: (o, ctx) => {
80
+ const value = o.titleTemplate ? o.titleTemplate.replace("%s", o.title ?? "") : o.title;
81
+ ctx.meta.unshift(`<title>${escapeHTML(value ?? "")}</title>`);
82
+ },
83
+ };
84
+ export const langStrategy = {
85
+ id: "lang",
86
+ applies: (o) => Boolean(o.lang),
87
+ applyDOM: (o) => {
88
+ if (o.lang)
89
+ document.documentElement.lang = o.lang;
90
+ },
91
+ applyHTML: (o, ctx) => {
92
+ if (o.lang)
93
+ ctx.meta.push(`<!-- lang:${o.lang} -->`);
94
+ },
95
+ };
96
+ export const descriptionStrategy = {
97
+ id: "description",
98
+ applies: (o) => Boolean(o.description),
99
+ applyDOM: (o, ctx) => {
100
+ if (o.description)
101
+ ctx.setMeta("description", o.description);
102
+ },
103
+ applyHTML: (o, ctx) => {
104
+ if (o.description)
105
+ ctx.meta.push(`<meta name="description" content="${escapeHTML(o.description)}" />`);
106
+ },
107
+ };
108
+ export const canonicalStrategy = {
109
+ id: "canonical",
110
+ applies: (o) => Boolean(o.canonical),
111
+ applyDOM: (o, ctx) => {
112
+ if (o.canonical)
113
+ ctx.setLink({ [ATTR.rel]: "canonical", [ATTR.href]: o.canonical });
114
+ },
115
+ applyHTML: (o, ctx) => {
116
+ if (o.canonical)
117
+ ctx.link.push(`<link rel="canonical" href="${escapeHTML(o.canonical)}" />`);
118
+ },
119
+ };
120
+ export const robotsStrategy = {
121
+ id: "robots",
122
+ applies: (o) => o.robots !== undefined,
123
+ applyDOM: (o, ctx) => {
124
+ if (o.robots === undefined)
125
+ return;
126
+ const meta = Array.isArray(o.robots) ? robotsDirectivesToMeta(o.robots) : o.robots;
127
+ ctx.setMeta("robots", robotsMetaToString(meta));
128
+ },
129
+ applyHTML: (o, ctx) => {
130
+ if (o.robots === undefined)
131
+ return;
132
+ const meta = Array.isArray(o.robots) ? robotsDirectivesToMeta(o.robots) : o.robots;
133
+ ctx.meta.push(`<meta name="robots" content="${escapeHTML(robotsMetaToString(meta))}" />`);
134
+ },
135
+ };
136
+ export const viewportStrategy = {
137
+ id: "viewport",
138
+ applies: (o) => Boolean(o.viewport),
139
+ applyDOM: (o, ctx) => {
140
+ if (o.viewport)
141
+ ctx.setMeta("viewport", o.viewport);
142
+ },
143
+ applyHTML: (o, ctx) => {
144
+ if (o.viewport)
145
+ ctx.meta.push(`<meta name="viewport" content="${escapeHTML(o.viewport)}" />`);
146
+ },
147
+ };
148
+ export const themeColorStrategy = {
149
+ id: "theme-color",
150
+ applies: (o) => Boolean(o.themeColor),
151
+ applyDOM: (o, ctx) => {
152
+ if (o.themeColor)
153
+ ctx.setMeta("theme-color", o.themeColor);
154
+ },
155
+ applyHTML: (o, ctx) => {
156
+ if (o.themeColor)
157
+ ctx.meta.push(`<meta name="theme-color" content="${escapeHTML(o.themeColor)}" />`);
158
+ },
159
+ };
160
+ export const faviconStrategy = {
161
+ id: "favicons",
162
+ applies: (o) => Boolean(o.favicon || o.appleTouchIcon || o.maskIcon),
163
+ applyDOM: (o, ctx) => {
164
+ if (o.favicon)
165
+ ctx.setLink({ [ATTR.rel]: "icon", [ATTR.type]: "image/x-icon", [ATTR.href]: o.favicon });
166
+ if (o.appleTouchIcon)
167
+ ctx.setLink({ [ATTR.rel]: "apple-touch-icon", [ATTR.sizes]: "180x180", [ATTR.href]: o.appleTouchIcon });
168
+ if (o.maskIcon)
169
+ ctx.setLink({ [ATTR.rel]: "mask-icon", [ATTR.href]: o.maskIcon });
170
+ },
171
+ applyHTML: (o, ctx) => {
172
+ if (o.favicon)
173
+ ctx.link.push(`<link rel="icon" type="image/x-icon" href="${escapeHTML(o.favicon)}" />`);
174
+ if (o.appleTouchIcon)
175
+ ctx.link.push(`<link rel="apple-touch-icon" sizes="180x180" href="${escapeHTML(o.appleTouchIcon)}" />`);
176
+ if (o.maskIcon)
177
+ ctx.link.push(`<link rel="mask-icon" href="${escapeHTML(o.maskIcon)}" />`);
178
+ },
179
+ };
180
+ export const hreflangStrategy = {
181
+ id: "hreflang",
182
+ applies: (o) => Boolean(o.hreflang && o.hreflang.length > 0),
183
+ applyDOM: (o, ctx) => {
184
+ if (!o.hreflang)
185
+ return;
186
+ document.querySelectorAll('link[rel="alternate"][hreflang]').forEach((el) => el.remove());
187
+ for (const entry of o.hreflang) {
188
+ ctx.setLink({ [ATTR.rel]: "alternate", [ATTR.hreflang]: entry.lang, [ATTR.href]: entry.url });
189
+ }
190
+ },
191
+ applyHTML: (o, ctx) => {
192
+ if (!o.hreflang)
193
+ return;
194
+ for (const entry of o.hreflang) {
195
+ ctx.link.push(`<link rel="alternate" hreflang="${escapeHTML(entry.lang)}" href="${escapeHTML(entry.url)}" />`);
196
+ }
197
+ },
198
+ };
199
+ const buildPreloadAttrs = (preload) => {
200
+ const attrs = { [ATTR.rel]: "preload", [ATTR.href]: preload.href, [ATTR.as]: preload.as };
201
+ if (preload.type)
202
+ attrs[ATTR.type] = preload.type;
203
+ if (preload.crossOrigin)
204
+ attrs[ATTR.crossorigin] = preload.crossOrigin;
205
+ if (preload.integrity)
206
+ attrs.integrity = preload.integrity;
207
+ return attrs;
208
+ };
209
+ const buildPreconnectAttrs = (origin) => {
210
+ const attrs = { [ATTR.rel]: "preconnect", [ATTR.href]: origin.href };
211
+ if (origin.crossOrigin)
212
+ attrs[ATTR.crossorigin] = origin.crossOrigin;
213
+ return attrs;
214
+ };
215
+ const htmlAttrs = (attrs) => Object.entries(attrs).map(([k, v]) => `${k}="${escapeHTML(v)}"`).join(" ");
216
+ export const preloadStrategy = {
217
+ id: "preload",
218
+ applies: (o) => Boolean(o.preload && o.preload.length > 0),
219
+ applyDOM: (o, ctx) => {
220
+ if (!o.preload)
221
+ return;
222
+ for (const preload of o.preload) {
223
+ const existing = document.querySelector(`link[rel="preload"][href="${preload.href}"]`);
224
+ if (existing)
225
+ existing.remove();
226
+ ctx.setLink(buildPreloadAttrs(preload));
227
+ }
228
+ },
229
+ applyHTML: (o, ctx) => {
230
+ if (!o.preload)
231
+ return;
232
+ for (const preload of o.preload) {
233
+ ctx.link.push(`<link ${htmlAttrs(buildPreloadAttrs(preload))} />`);
234
+ }
235
+ },
236
+ };
237
+ export const preconnectStrategy = {
238
+ id: "preconnect",
239
+ applies: (o) => Boolean(o.preconnect && o.preconnect.length > 0),
240
+ applyDOM: (o, ctx) => {
241
+ if (!o.preconnect)
242
+ return;
243
+ for (const origin of o.preconnect)
244
+ ctx.setLink(buildPreconnectAttrs(origin));
245
+ },
246
+ applyHTML: (o, ctx) => {
247
+ if (!o.preconnect)
248
+ return;
249
+ for (const origin of o.preconnect)
250
+ ctx.link.push(`<link ${htmlAttrs(buildPreconnectAttrs(origin))} />`);
251
+ },
252
+ };
253
+ export const dnsPrefetchStrategy = {
254
+ id: "dns-prefetch",
255
+ applies: (o) => Boolean(o.dnsPrefetch && o.dnsPrefetch.length > 0),
256
+ applyDOM: (o, ctx) => {
257
+ if (!o.dnsPrefetch)
258
+ return;
259
+ for (const domain of o.dnsPrefetch) {
260
+ ctx.setLink({ [ATTR.rel]: "dns-prefetch", [ATTR.href]: domain.href });
261
+ }
262
+ },
263
+ applyHTML: (o, ctx) => {
264
+ if (!o.dnsPrefetch)
265
+ return;
266
+ for (const domain of o.dnsPrefetch) {
267
+ ctx.link.push(`<link rel="dns-prefetch" href="${escapeHTML(domain.href)}" />`);
268
+ }
269
+ },
270
+ };
271
+ export const customMetaStrategy = {
272
+ id: "custom-meta",
273
+ applies: (o) => Boolean(o.meta && o.meta.length > 0),
274
+ applyDOM: (o, ctx) => {
275
+ if (!o.meta)
276
+ return;
277
+ for (const m of o.meta) {
278
+ if (m.name)
279
+ ctx.setMeta(m.name, m.content);
280
+ else if (m.property)
281
+ ctx.setMeta(m.property, m.content);
282
+ else if (m.httpEquiv)
283
+ ctx.setMeta(m.httpEquiv, m.content);
284
+ }
285
+ },
286
+ applyHTML: (o, ctx) => {
287
+ if (!o.meta)
288
+ return;
289
+ for (const m of o.meta) {
290
+ if (m.name)
291
+ ctx.meta.push(`<meta name="${escapeHTML(m.name)}" content="${escapeHTML(m.content)}" />`);
292
+ else if (m.property)
293
+ ctx.meta.push(`<meta property="${escapeHTML(m.property)}" content="${escapeHTML(m.content)}" />`);
294
+ else if (m.httpEquiv)
295
+ ctx.meta.push(`<meta http-equiv="${escapeHTML(m.httpEquiv)}" content="${escapeHTML(m.content)}" />`);
296
+ }
297
+ },
298
+ };
299
+ export const customLinkStrategy = {
300
+ id: "custom-link",
301
+ applies: (o) => Boolean(o.link && o.link.length > 0),
302
+ applyDOM: (o, ctx) => {
303
+ if (!o.link)
304
+ return;
305
+ for (const link of o.link) {
306
+ const attrs = { [ATTR.rel]: link.rel, [ATTR.href]: link.href };
307
+ if (link.type)
308
+ attrs[ATTR.type] = link.type;
309
+ if (link.sizes)
310
+ attrs[ATTR.sizes] = link.sizes;
311
+ if (link.media)
312
+ attrs[ATTR.media] = link.media;
313
+ if (link.crossOrigin)
314
+ attrs[ATTR.crossorigin] = link.crossOrigin;
315
+ if (link.as)
316
+ attrs[ATTR.as] = link.as;
317
+ ctx.setLink(attrs);
318
+ }
319
+ },
320
+ applyHTML: (o, ctx) => {
321
+ if (!o.link)
322
+ return;
323
+ for (const link of o.link) {
324
+ const attrs = { [ATTR.rel]: link.rel, [ATTR.href]: link.href };
325
+ if (link.type)
326
+ attrs[ATTR.type] = link.type;
327
+ if (link.sizes)
328
+ attrs[ATTR.sizes] = link.sizes;
329
+ if (link.media)
330
+ attrs[ATTR.media] = link.media;
331
+ if (link.crossOrigin)
332
+ attrs[ATTR.crossorigin] = link.crossOrigin;
333
+ if (link.as)
334
+ attrs[ATTR.as] = link.as;
335
+ ctx.link.push(`<link ${htmlAttrs(attrs)} />`);
336
+ }
337
+ },
338
+ };
339
+ const ogProperty = (name, value, ctx) => {
340
+ if (!value)
341
+ return;
342
+ ctx.meta.push(`<meta property="og:${name}" content="${escapeHTML(value)}" />`);
343
+ };
344
+ const ogImageTags = (image) => {
345
+ const sink = { meta: [] };
346
+ if (!image)
347
+ return sink;
348
+ if (Array.isArray(image)) {
349
+ for (const img of image) {
350
+ ogProperty("image", img.url, sink);
351
+ if (img.width)
352
+ ogProperty("image:width", String(img.width), sink);
353
+ if (img.height)
354
+ ogProperty("image:height", String(img.height), sink);
355
+ if (img.alt)
356
+ ogProperty("image:alt", img.alt, sink);
357
+ if (img.type)
358
+ ogProperty("image:type", img.type, sink);
359
+ if (img.secureUrl)
360
+ ogProperty("image:secure_url", img.secureUrl, sink);
361
+ }
362
+ }
363
+ else {
364
+ ogProperty("image", image, sink);
365
+ }
366
+ return sink;
367
+ };
368
+ export const openGraphStrategy = {
369
+ id: "open-graph",
370
+ applies: (o) => Boolean(o.openGraph),
371
+ applyDOM: (o, ctx) => {
372
+ const og = o.openGraph;
373
+ if (!og)
374
+ return;
375
+ if (og.title)
376
+ ctx.setMeta("og:title", og.title);
377
+ if (og.description)
378
+ ctx.setMeta("og:description", og.description);
379
+ if (og.url)
380
+ ctx.setMeta("og:url", og.url);
381
+ if (og.type)
382
+ ctx.setMeta("og:type", og.type);
383
+ if (og.siteName)
384
+ ctx.setMeta("og:site_name", og.siteName);
385
+ if (og.locale)
386
+ ctx.setMeta("og:locale", og.locale);
387
+ if (og.image) {
388
+ if (Array.isArray(og.image)) {
389
+ for (const img of og.image) {
390
+ ctx.setMeta("og:image", img.url);
391
+ if (img.secureUrl)
392
+ ctx.setMeta("og:image:secure_url", img.secureUrl);
393
+ if (img.type)
394
+ ctx.setMeta("og:image:type", img.type);
395
+ if (img.width)
396
+ ctx.setMeta("og:image:width", String(img.width));
397
+ if (img.height)
398
+ ctx.setMeta("og:image:height", String(img.height));
399
+ if (img.alt)
400
+ ctx.setMeta("og:image:alt", img.alt);
401
+ }
402
+ }
403
+ else {
404
+ ctx.setMeta("og:image", og.image);
405
+ }
406
+ }
407
+ if (og.alternateLocale) {
408
+ og.alternateLocale.forEach((locale, index) => {
409
+ ctx.setMeta(`og:locale:alternate${index > 0 ? `:${index}` : ""}`, locale);
410
+ });
411
+ }
412
+ if (og.type === "article" && og.article) {
413
+ ctx.setMeta("og:article:published_time", og.article.publishedTime);
414
+ ctx.setMeta("og:article:modified_time", og.article.modifiedTime);
415
+ ctx.setMeta("og:article:expiration_time", og.article.expirationTime);
416
+ ctx.setMeta("og:article:author", og.article.author);
417
+ ctx.setMeta("og:article:section", og.article.section);
418
+ og.article.tag?.forEach((tag, index) => {
419
+ ctx.setMeta(`og:article:tag${index > 0 ? `:${index}` : ""}`, tag);
420
+ });
421
+ }
422
+ if (og.type === "product" && og.product) {
423
+ ctx.setMeta("og:product:price:amount", String(og.product.price));
424
+ ctx.setMeta("og:product:price:currency", og.product.priceCurrency);
425
+ ctx.setMeta("og:product:availability", og.product.availability);
426
+ ctx.setMeta("og:product:brand", og.product.brand);
427
+ ctx.setMeta("og:product:sku", og.product.sku);
428
+ ctx.setMeta("og:product:condition", og.product.condition);
429
+ }
430
+ if (og.type === "profile") {
431
+ ctx.setMeta("og:profile:first_name", og.firstName);
432
+ ctx.setMeta("og:profile:last_name", og.lastName);
433
+ ctx.setMeta("og:profile:username", og.username);
434
+ }
435
+ if (og.type === "music" && og.music) {
436
+ ctx.setMeta("og:music:album", og.music.album);
437
+ ctx.setMeta("og:music:musician", og.music.musician);
438
+ ctx.setMeta("og:music:song", og.music.song);
439
+ ctx.setMeta("og:music:release_date", og.music.releaseDate);
440
+ ctx.setMeta("og:music:duration", og.music.duration);
441
+ ctx.setMeta("og:music:creator", og.music.creator);
442
+ }
443
+ },
444
+ applyHTML: (o, ctx) => {
445
+ const og = o.openGraph;
446
+ if (!og)
447
+ return;
448
+ ogProperty("title", og.title, ctx);
449
+ ogProperty("description", og.description, ctx);
450
+ ogProperty("url", og.url, ctx);
451
+ ogProperty("type", og.type, ctx);
452
+ ogProperty("site_name", og.siteName, ctx);
453
+ ogProperty("locale", og.locale, ctx);
454
+ const imageSink = ogImageTags(og.image);
455
+ ctx.meta.push(...imageSink.meta);
456
+ og.alternateLocale?.forEach((locale, index) => {
457
+ ctx.meta.push(`<meta property="og:locale:alternate${index > 0 ? `:${index}` : ""}" content="${escapeHTML(locale)}" />`);
458
+ });
459
+ if (og.type === "article" && og.article) {
460
+ ogProperty("article:published_time", og.article.publishedTime, ctx);
461
+ ogProperty("article:modified_time", og.article.modifiedTime, ctx);
462
+ ogProperty("article:expiration_time", og.article.expirationTime, ctx);
463
+ ogProperty("article:author", og.article.author, ctx);
464
+ ogProperty("article:section", og.article.section, ctx);
465
+ og.article.tag?.forEach((tag, index) => {
466
+ ctx.meta.push(`<meta property="og:article:tag${index > 0 ? `:${index}` : ""}" content="${escapeHTML(tag)}" />`);
467
+ });
468
+ }
469
+ if (og.type === "product" && og.product) {
470
+ ogProperty("product:price:amount", String(og.product.price), ctx);
471
+ ogProperty("product:price:currency", og.product.priceCurrency, ctx);
472
+ ogProperty("product:availability", og.product.availability, ctx);
473
+ ogProperty("product:brand", og.product.brand, ctx);
474
+ ogProperty("product:sku", og.product.sku, ctx);
475
+ ogProperty("product:condition", og.product.condition, ctx);
476
+ }
477
+ if (og.type === "profile") {
478
+ ogProperty("profile:first_name", og.firstName, ctx);
479
+ ogProperty("profile:last_name", og.lastName, ctx);
480
+ ogProperty("profile:username", og.username, ctx);
481
+ }
482
+ if (og.type === "music" && og.music) {
483
+ ogProperty("music:album", og.music.album, ctx);
484
+ ogProperty("music:musician", og.music.musician, ctx);
485
+ ogProperty("music:song", og.music.song, ctx);
486
+ ogProperty("music:release_date", og.music.releaseDate, ctx);
487
+ ogProperty("music:duration", og.music.duration, ctx);
488
+ ogProperty("music:creator", og.music.creator, ctx);
489
+ }
490
+ },
491
+ };
492
+ const twitterFallback = (twitter, openGraph) => ({
493
+ cardType: twitter.cardType,
494
+ site: twitter.site,
495
+ handle: twitter.handle,
496
+ title: twitter.title ?? openGraph?.title,
497
+ description: twitter.description ?? openGraph?.description,
498
+ image: twitter.image ?? (typeof openGraph?.image === "string" ? openGraph.image : undefined),
499
+ imageAlt: twitter.imageAlt,
500
+ player: twitter.player,
501
+ playerWidth: twitter.playerWidth,
502
+ playerHeight: twitter.playerHeight,
503
+ playerStream: twitter.playerStream,
504
+ playerStreamContentType: twitter.playerStreamContentType,
505
+ app: twitter.app,
506
+ });
507
+ export const twitterStrategy = {
508
+ id: "twitter",
509
+ applies: (o) => Boolean(o.twitter),
510
+ applyDOM: (o, ctx) => {
511
+ if (!o.twitter)
512
+ return;
513
+ const tw = twitterFallback(o.twitter, o.openGraph);
514
+ if (tw.cardType)
515
+ ctx.setMeta("twitter:card", tw.cardType);
516
+ if (tw.site)
517
+ ctx.setMeta("twitter:site", tw.site);
518
+ if (tw.handle)
519
+ ctx.setMeta("twitter:creator", tw.handle);
520
+ if (tw.title)
521
+ ctx.setMeta("twitter:title", tw.title);
522
+ if (tw.description)
523
+ ctx.setMeta("twitter:description", tw.description);
524
+ if (tw.image)
525
+ ctx.setMeta("twitter:image", tw.image);
526
+ if (tw.imageAlt)
527
+ ctx.setMeta("twitter:image:alt", tw.imageAlt);
528
+ if (tw.cardType === "player") {
529
+ ctx.setMeta("twitter:player", tw.player);
530
+ ctx.setMeta("twitter:player:width", tw.playerWidth);
531
+ ctx.setMeta("twitter:player:height", tw.playerHeight);
532
+ ctx.setMeta("twitter:player:stream", tw.playerStream);
533
+ ctx.setMeta("twitter:player:stream:content_type", tw.playerStreamContentType);
534
+ }
535
+ if (tw.app?.iphone) {
536
+ ctx.setMeta("twitter:app:name:iphone", tw.app.iphone.name);
537
+ ctx.setMeta("twitter:app:id:iphone", tw.app.iphone.id);
538
+ ctx.setMeta("twitter:app:url:iphone", tw.app.iphone.url);
539
+ }
540
+ if (tw.app?.ipad) {
541
+ ctx.setMeta("twitter:app:name:ipad", tw.app.ipad.name);
542
+ ctx.setMeta("twitter:app:id:ipad", tw.app.ipad.id);
543
+ ctx.setMeta("twitter:app:url:ipad", tw.app.ipad.url);
544
+ }
545
+ if (tw.app?.googleplay) {
546
+ ctx.setMeta("twitter:app:name:googleplay", tw.app.googleplay.name);
547
+ ctx.setMeta("twitter:app:id:googleplay", tw.app.googleplay.id);
548
+ ctx.setMeta("twitter:app:url:googleplay", tw.app.googleplay.url);
549
+ }
550
+ },
551
+ applyHTML: (o, ctx) => {
552
+ if (!o.twitter)
553
+ return;
554
+ const tw = twitterFallback(o.twitter, o.openGraph);
555
+ const push = (name, value) => {
556
+ if (value)
557
+ ctx.meta.push(`<meta name="twitter:${name}" content="${escapeHTML(value)}" />`);
558
+ };
559
+ push("card", tw.cardType);
560
+ push("site", tw.site);
561
+ push("creator", tw.handle);
562
+ push("title", tw.title);
563
+ push("description", tw.description);
564
+ push("image", tw.image);
565
+ push("image:alt", tw.imageAlt);
566
+ if (tw.cardType === "player") {
567
+ push("player", tw.player);
568
+ push("player:width", tw.playerWidth);
569
+ push("player:height", tw.playerHeight);
570
+ push("player:stream", tw.playerStream);
571
+ push("player:stream:content_type", tw.playerStreamContentType);
572
+ }
573
+ if (tw.app?.iphone) {
574
+ push("app:name:iphone", tw.app.iphone.name);
575
+ push("app:id:iphone", tw.app.iphone.id);
576
+ push("app:url:iphone", tw.app.iphone.url);
577
+ }
578
+ if (tw.app?.ipad) {
579
+ push("app:name:ipad", tw.app.ipad.name);
580
+ push("app:id:ipad", tw.app.ipad.id);
581
+ push("app:url:ipad", tw.app.ipad.url);
582
+ }
583
+ if (tw.app?.googleplay) {
584
+ push("app:name:googleplay", tw.app.googleplay.name);
585
+ push("app:id:googleplay", tw.app.googleplay.id);
586
+ push("app:url:googleplay", tw.app.googleplay.url);
587
+ }
588
+ },
589
+ };
590
+ export const jsonLdStrategy = {
591
+ id: "json-ld",
592
+ applies: (o) => Boolean(o.jsonLd && o.jsonLd.length > 0),
593
+ applyDOM: () => {
594
+ },
595
+ applyHTML: (o, ctx) => {
596
+ if (!o.jsonLd)
597
+ return;
598
+ for (const data of o.jsonLd) {
599
+ ctx.jsonLd.push(`<script type="application/ld+json">${escapeJSONForScript(JSON.stringify(data))}</script>`);
600
+ }
601
+ },
602
+ };
603
+ export const SEO_STRATEGIES = Object.freeze([
604
+ titleStrategy,
605
+ descriptionStrategy,
606
+ canonicalStrategy,
607
+ robotsStrategy,
608
+ viewportStrategy,
609
+ themeColorStrategy,
610
+ faviconStrategy,
611
+ hreflangStrategy,
612
+ preloadStrategy,
613
+ preconnectStrategy,
614
+ dnsPrefetchStrategy,
615
+ customMetaStrategy,
616
+ customLinkStrategy,
617
+ openGraphStrategy,
618
+ twitterStrategy,
619
+ jsonLdStrategy,
620
+ ]);
@@ -0,0 +1,16 @@
1
+ import type { SEOptions } from "../types/index.js";
2
+ export interface DOMContext {
3
+ setMeta: (name: string, content: string | undefined) => void;
4
+ setLink: (attrs: Record<string, string>) => void;
5
+ }
6
+ export interface HTMLContext {
7
+ meta: string[];
8
+ link: string[];
9
+ jsonLd: string[];
10
+ }
11
+ export interface Strategy {
12
+ readonly id: string;
13
+ applies(options: SEOptions): boolean;
14
+ applyDOM(options: SEOptions, ctx: DOMContext): void;
15
+ applyHTML(options: SEOptions, ctx: HTMLContext): void;
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,2 @@
1
- /**
2
- * SEO Hooks
3
- *
4
- * React hooks for SEO management
5
- */
6
1
  export { useSEO } from "./useSEO.js";
7
2
  export { useJsonLd } from "./useJsonLd.js";
@@ -1,7 +1,2 @@
1
- /**
2
- * SEO Hooks
3
- *
4
- * React hooks for SEO management
5
- */
6
1
  export { useSEO } from "./useSEO.js";
7
2
  export { useJsonLd } from "./useJsonLd.js";
@@ -1,18 +1,10 @@
1
- /**
2
- * useJsonLd Hook
3
- *
4
- * React hook for managing JSON-LD structured data.
5
- * Provides a programmatic way to add/update/remove structured data.
6
- */
7
1
  import type { JsonLdTypes } from "../types/schema.js";
8
2
  interface UseJsonLdOptions {
9
- /** Strategy for when to inject the script tag */
10
3
  strategy?: "afterInteractive" | "beforeInteractive" | "idle";
11
- /** Unique identifier for this JSON-LD block */
12
4
  id?: string;
13
5
  }
14
6
  export declare const useJsonLd: (data: JsonLdTypes | JsonLdTypes[], options?: UseJsonLdOptions) => {
15
- injectJsonLd: (jsonData: JsonLdTypes | JsonLdTypes[]) => void;
7
+ injectJsonLd: (payload: JsonLdTypes | JsonLdTypes[]) => void;
16
8
  removeJsonLd: () => void;
17
9
  };
18
- export default useJsonLd;
10
+ export {};