@umituz/web-seo 1.0.5 → 2.0.4
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 +433 -0
- package/dist/domains/seo/components/JsonLd.d.ts +17 -0
- package/dist/domains/seo/components/JsonLd.d.ts.map +1 -0
- package/dist/domains/seo/components/JsonLd.js +52 -0
- package/dist/domains/seo/components/SEO.d.ts +4 -0
- package/dist/domains/seo/components/SEO.d.ts.map +1 -0
- package/dist/domains/seo/components/SEO.js +48 -0
- package/dist/domains/seo/core/init.d.ts +16 -0
- package/dist/domains/seo/core/init.d.ts.map +1 -0
- package/dist/domains/seo/core/init.js +34 -0
- package/dist/domains/seo/hooks/useJsonLd.d.ts +19 -0
- package/dist/domains/seo/hooks/useJsonLd.d.ts.map +1 -0
- package/dist/domains/seo/hooks/useJsonLd.js +53 -0
- package/dist/domains/seo/hooks/useSEO.d.ts +3 -0
- package/dist/domains/seo/hooks/useSEO.d.ts.map +1 -0
- package/dist/domains/seo/hooks/useSEO.js +47 -0
- package/dist/domains/seo/index.d.ts +15 -0
- package/dist/domains/seo/index.d.ts.map +1 -0
- package/dist/domains/seo/index.js +21 -0
- package/dist/domains/seo/ssr/renderer.d.ts +58 -0
- package/dist/domains/seo/ssr/renderer.d.ts.map +1 -0
- package/dist/domains/seo/ssr/renderer.js +242 -0
- package/dist/domains/seo/ssr/serializer.d.ts +71 -0
- package/dist/domains/seo/ssr/serializer.d.ts.map +1 -0
- package/dist/domains/seo/ssr/serializer.js +175 -0
- package/dist/domains/seo/types/index.d.ts +190 -0
- package/dist/domains/seo/types/index.d.ts.map +1 -0
- package/dist/domains/seo/types/index.js +1 -0
- package/dist/domains/seo/types/schema.d.ts +212 -0
- package/dist/domains/seo/types/schema.d.ts.map +1 -0
- package/dist/domains/seo/types/schema.js +4 -0
- package/dist/domains/seo/utils/dom.d.ts +22 -0
- package/dist/domains/seo/utils/dom.d.ts.map +1 -0
- package/dist/domains/seo/utils/dom.js +537 -0
- package/dist/domains/seo/utils/schema.d.ts +135 -0
- package/dist/domains/seo/utils/schema.d.ts.map +1 -0
- package/dist/domains/seo/utils/schema.js +321 -0
- package/dist/domains/seo/utils/validators.d.ts +39 -0
- package/dist/domains/seo/utils/validators.d.ts.map +1 -0
- package/dist/domains/seo/utils/validators.js +364 -0
- package/dist/domains/seo/vite/plugin.d.ts +61 -0
- package/dist/domains/seo/vite/plugin.d.ts.map +1 -0
- package/dist/domains/seo/vite/plugin.js +215 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/package.json +34 -5
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEO DOM Utilities
|
|
3
|
+
*
|
|
4
|
+
* Core utilities for manipulating DOM elements related to SEO.
|
|
5
|
+
* Handles meta tags, link tags, structured data, and performance hints.
|
|
6
|
+
*/
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Meta Tag Management
|
|
9
|
+
// ============================================================================
|
|
10
|
+
const setMetaTag = (attrName, attrValue, content) => {
|
|
11
|
+
if (typeof document === "undefined")
|
|
12
|
+
return;
|
|
13
|
+
let element = document.querySelector(`meta[${attrName}="${attrValue}"]`);
|
|
14
|
+
if (!element) {
|
|
15
|
+
element = document.createElement("meta");
|
|
16
|
+
element.setAttribute(attrName, attrValue);
|
|
17
|
+
document.head.appendChild(element);
|
|
18
|
+
}
|
|
19
|
+
if (content) {
|
|
20
|
+
element.setAttribute("content", content);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const setLinkTag = (attrs) => {
|
|
24
|
+
if (typeof document === "undefined")
|
|
25
|
+
return;
|
|
26
|
+
const rel = attrs.rel;
|
|
27
|
+
if (!rel)
|
|
28
|
+
return;
|
|
29
|
+
// Build selector based on rel and other identifying attributes
|
|
30
|
+
let selector = `link[rel="${rel}"]`;
|
|
31
|
+
if (attrs.href)
|
|
32
|
+
selector += `[href="${attrs.href}"]`;
|
|
33
|
+
if (attrs.sizes)
|
|
34
|
+
selector += `[sizes="${attrs.sizes}"]`;
|
|
35
|
+
if (attrs.type)
|
|
36
|
+
selector += `[type="${attrs.type}"]`;
|
|
37
|
+
let element = document.querySelector(selector);
|
|
38
|
+
if (!element) {
|
|
39
|
+
element = document.createElement("link");
|
|
40
|
+
document.head.appendChild(element);
|
|
41
|
+
}
|
|
42
|
+
Object.entries(attrs).forEach(([key, value]) => {
|
|
43
|
+
element.setAttribute(key, value);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// Robots Meta Tag
|
|
48
|
+
// ============================================================================
|
|
49
|
+
const setRobotsMeta = (robots) => {
|
|
50
|
+
if (typeof document === "undefined")
|
|
51
|
+
return;
|
|
52
|
+
let content = "";
|
|
53
|
+
if (typeof robots === "boolean") {
|
|
54
|
+
content = robots ? "index, follow" : "noindex, nofollow";
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const directives = [];
|
|
58
|
+
if (robots.index !== undefined) {
|
|
59
|
+
directives.push(robots.index ? "index" : "noindex");
|
|
60
|
+
}
|
|
61
|
+
if (robots.follow !== undefined) {
|
|
62
|
+
directives.push(robots.follow ? "follow" : "nofollow");
|
|
63
|
+
}
|
|
64
|
+
if (robots.archive !== undefined) {
|
|
65
|
+
directives.push(robots.archive ? "all" : "noarchive");
|
|
66
|
+
}
|
|
67
|
+
if (robots.snippet !== undefined) {
|
|
68
|
+
directives.push(robots.snippet ? "all" : "nosnippet");
|
|
69
|
+
}
|
|
70
|
+
if (robots.translate !== undefined) {
|
|
71
|
+
directives.push(robots.translate ? "all" : "notranslate");
|
|
72
|
+
}
|
|
73
|
+
if (robots.imageIndex !== undefined) {
|
|
74
|
+
directives.push(robots.imageIndex ? "all" : "noimageindex");
|
|
75
|
+
}
|
|
76
|
+
if (robots.maxSnippet !== undefined) {
|
|
77
|
+
directives.push(`max-snippet:${robots.maxSnippet}`);
|
|
78
|
+
}
|
|
79
|
+
if (robots.maxImagePreview !== undefined) {
|
|
80
|
+
directives.push(`max-image-preview:${robots.maxImagePreview}`);
|
|
81
|
+
}
|
|
82
|
+
if (robots.maxVideoPreview !== undefined) {
|
|
83
|
+
directives.push(`max-video-preview:${robots.maxVideoPreview}`);
|
|
84
|
+
}
|
|
85
|
+
if (robots.unavailableAfter !== undefined) {
|
|
86
|
+
directives.push(`unavailable_after:${robots.unavailableAfter}`);
|
|
87
|
+
}
|
|
88
|
+
content = directives.join(", ");
|
|
89
|
+
}
|
|
90
|
+
setMetaTag("name", "robots", content);
|
|
91
|
+
};
|
|
92
|
+
// ============================================================================
|
|
93
|
+
// Hreflang Management
|
|
94
|
+
// ============================================================================
|
|
95
|
+
const setHreflangTags = (hreflang) => {
|
|
96
|
+
if (typeof document === "undefined")
|
|
97
|
+
return;
|
|
98
|
+
// Remove existing hreflang tags
|
|
99
|
+
document.querySelectorAll('link[rel="alternate"][hreflang]').forEach((el) => el.remove());
|
|
100
|
+
// Add new hreflang tags
|
|
101
|
+
hreflang.forEach((entry) => {
|
|
102
|
+
setLinkTag({
|
|
103
|
+
rel: "alternate",
|
|
104
|
+
hreflang: entry.lang,
|
|
105
|
+
href: entry.url,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
// ============================================================================
|
|
110
|
+
// Favicon Management
|
|
111
|
+
// ============================================================================
|
|
112
|
+
const setFavicon = (href) => {
|
|
113
|
+
if (typeof document === "undefined")
|
|
114
|
+
return;
|
|
115
|
+
setLinkTag({ rel: "icon", href, type: "image/x-icon" });
|
|
116
|
+
};
|
|
117
|
+
const setAppleTouchIcon = (href) => {
|
|
118
|
+
if (typeof document === "undefined")
|
|
119
|
+
return;
|
|
120
|
+
setLinkTag({ rel: "apple-touch-icon", href, sizes: "180x180" });
|
|
121
|
+
};
|
|
122
|
+
const setMaskIcon = (href, color) => {
|
|
123
|
+
if (typeof document === "undefined")
|
|
124
|
+
return;
|
|
125
|
+
setLinkTag({ rel: "mask-icon", href, ...(color && { color }) });
|
|
126
|
+
};
|
|
127
|
+
// ============================================================================
|
|
128
|
+
// Theme Color
|
|
129
|
+
// ============================================================================
|
|
130
|
+
const setThemeColor = (color) => {
|
|
131
|
+
if (typeof document === "undefined")
|
|
132
|
+
return;
|
|
133
|
+
setMetaTag("name", "theme-color", color);
|
|
134
|
+
};
|
|
135
|
+
// ============================================================================
|
|
136
|
+
// Viewport
|
|
137
|
+
// ============================================================================
|
|
138
|
+
const setViewport = (content) => {
|
|
139
|
+
if (typeof document === "undefined")
|
|
140
|
+
return;
|
|
141
|
+
setMetaTag("name", "viewport", content);
|
|
142
|
+
};
|
|
143
|
+
// ============================================================================
|
|
144
|
+
// Performance Hints
|
|
145
|
+
// ============================================================================
|
|
146
|
+
const setPreloadHints = (preloads) => {
|
|
147
|
+
if (typeof document === "undefined")
|
|
148
|
+
return;
|
|
149
|
+
// Remove existing preload hints for same resources
|
|
150
|
+
preloads.forEach((preload) => {
|
|
151
|
+
const existing = document.querySelector(`link[rel="preload"][href="${preload.href}"]`);
|
|
152
|
+
if (existing)
|
|
153
|
+
existing.remove();
|
|
154
|
+
});
|
|
155
|
+
// Add preload hints
|
|
156
|
+
preloads.forEach((preload) => {
|
|
157
|
+
const attrs = {
|
|
158
|
+
rel: "preload",
|
|
159
|
+
href: preload.href,
|
|
160
|
+
as: preload.as,
|
|
161
|
+
};
|
|
162
|
+
if (preload.type)
|
|
163
|
+
attrs.type = preload.type;
|
|
164
|
+
if (preload.crossOrigin)
|
|
165
|
+
attrs.crossorigin = preload.crossOrigin;
|
|
166
|
+
if (preload.integrity)
|
|
167
|
+
attrs.integrity = preload.integrity;
|
|
168
|
+
setLinkTag(attrs);
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
const setPreconnectHints = (origins) => {
|
|
172
|
+
if (typeof document === "undefined")
|
|
173
|
+
return;
|
|
174
|
+
origins.forEach((origin) => {
|
|
175
|
+
const attrs = {
|
|
176
|
+
rel: "preconnect",
|
|
177
|
+
href: origin.href,
|
|
178
|
+
};
|
|
179
|
+
if (origin.crossOrigin)
|
|
180
|
+
attrs.crossorigin = origin.crossOrigin;
|
|
181
|
+
setLinkTag(attrs);
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
const setDnsPrefetchHints = (domains) => {
|
|
185
|
+
if (typeof document === "undefined")
|
|
186
|
+
return;
|
|
187
|
+
domains.forEach((domain) => {
|
|
188
|
+
setLinkTag({
|
|
189
|
+
rel: "dns-prefetch",
|
|
190
|
+
href: domain.href,
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
// ============================================================================
|
|
195
|
+
// Open Graph (Enhanced)
|
|
196
|
+
// ============================================================================
|
|
197
|
+
const setOpenGraph = (openGraph) => {
|
|
198
|
+
if (!openGraph)
|
|
199
|
+
return;
|
|
200
|
+
const setOG = (property, content) => {
|
|
201
|
+
if (content)
|
|
202
|
+
setMetaTag("property", `og:${property}`, content);
|
|
203
|
+
};
|
|
204
|
+
setOG("title", openGraph.title);
|
|
205
|
+
setOG("description", openGraph.description);
|
|
206
|
+
setOG("url", openGraph.url);
|
|
207
|
+
setOG("type", openGraph.type);
|
|
208
|
+
setOG("site_name", openGraph.siteName);
|
|
209
|
+
setOG("locale", openGraph.locale);
|
|
210
|
+
// Handle multiple images
|
|
211
|
+
if (openGraph.image) {
|
|
212
|
+
if (Array.isArray(openGraph.image)) {
|
|
213
|
+
openGraph.image.forEach((img, index) => {
|
|
214
|
+
const suffix = index > 0 ? `:${index}` : "";
|
|
215
|
+
setOG(`image${suffix}`, img.url);
|
|
216
|
+
if (img.secureUrl)
|
|
217
|
+
setOG(`image:secure_url${suffix}`, img.secureUrl);
|
|
218
|
+
if (img.type)
|
|
219
|
+
setOG(`image:type${suffix}`, img.type);
|
|
220
|
+
if (img.width)
|
|
221
|
+
setOG(`image:width${suffix}`, String(img.width));
|
|
222
|
+
if (img.height)
|
|
223
|
+
setOG(`image:height${suffix}`, String(img.height));
|
|
224
|
+
if (img.alt)
|
|
225
|
+
setOG(`image:alt${suffix}`, img.alt);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
setOG("image", openGraph.image);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Alternate locales
|
|
233
|
+
if (openGraph.alternateLocale) {
|
|
234
|
+
openGraph.alternateLocale.forEach((locale, index) => {
|
|
235
|
+
setMetaTag("property", `og:locale:alternate${index > 0 ? `:${index}` : ""}`, locale);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
// Article specific
|
|
239
|
+
if (openGraph.type === "article" && openGraph.article) {
|
|
240
|
+
setOG("article:published_time", openGraph.article.publishedTime);
|
|
241
|
+
setOG("article:modified_time", openGraph.article.modifiedTime);
|
|
242
|
+
setOG("article:expiration_time", openGraph.article.expirationTime);
|
|
243
|
+
setOG("article:author", openGraph.article.author);
|
|
244
|
+
setOG("article:section", openGraph.article.section);
|
|
245
|
+
if (openGraph.article.tag) {
|
|
246
|
+
openGraph.article.tag.forEach((tag, index) => {
|
|
247
|
+
setMetaTag("property", `og:article:tag${index > 0 ? `:${index}` : ""}`, tag);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Product specific
|
|
252
|
+
if (openGraph.type === "product" && openGraph.product) {
|
|
253
|
+
setOG("product:price:amount", String(openGraph.product.price));
|
|
254
|
+
setOG("product:price:currency", openGraph.product.priceCurrency);
|
|
255
|
+
setOG("product:availability", openGraph.product.availability);
|
|
256
|
+
setOG("product:brand", openGraph.product.brand);
|
|
257
|
+
setOG("product:sku", openGraph.product.sku);
|
|
258
|
+
setOG("product:condition", openGraph.product.condition);
|
|
259
|
+
}
|
|
260
|
+
// Profile
|
|
261
|
+
if (openGraph.type === "profile") {
|
|
262
|
+
setOG("profile:first_name", openGraph.firstName);
|
|
263
|
+
setOG("profile:last_name", openGraph.lastName);
|
|
264
|
+
setOG("profile:username", openGraph.username);
|
|
265
|
+
}
|
|
266
|
+
// Music
|
|
267
|
+
if (openGraph.type === "music" && openGraph.music) {
|
|
268
|
+
setOG("music:album", openGraph.music.album);
|
|
269
|
+
setOG("music:musician", openGraph.music.musician);
|
|
270
|
+
setOG("music:song", openGraph.music.song);
|
|
271
|
+
setOG("music:release_date", openGraph.music.releaseDate);
|
|
272
|
+
setOG("music:duration", openGraph.music.duration);
|
|
273
|
+
setOG("music:creator", openGraph.music.creator);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
// ============================================================================
|
|
277
|
+
// Twitter Card (Enhanced)
|
|
278
|
+
// ============================================================================
|
|
279
|
+
const setTwitterCard = (twitter, _openGraphImage) => {
|
|
280
|
+
if (!twitter)
|
|
281
|
+
return;
|
|
282
|
+
const setTW = (name, content) => {
|
|
283
|
+
if (content)
|
|
284
|
+
setMetaTag("name", `twitter:${name}`, content);
|
|
285
|
+
};
|
|
286
|
+
setTW("card", twitter.cardType);
|
|
287
|
+
setTW("site", twitter.site);
|
|
288
|
+
setTW("creator", twitter.handle);
|
|
289
|
+
setTW("title", twitter.title);
|
|
290
|
+
setTW("description", twitter.description);
|
|
291
|
+
setTW("image", twitter.image);
|
|
292
|
+
setTW("image:alt", twitter.imageAlt);
|
|
293
|
+
// Player
|
|
294
|
+
if (twitter.cardType === "player") {
|
|
295
|
+
setTW("player", twitter.player);
|
|
296
|
+
setTW("player:width", twitter.playerWidth);
|
|
297
|
+
setTW("player:height", twitter.playerHeight);
|
|
298
|
+
setTW("player:stream", twitter.playerStream);
|
|
299
|
+
setTW("player:stream:content_type", twitter.playerStreamContentType);
|
|
300
|
+
}
|
|
301
|
+
// App
|
|
302
|
+
if (twitter.app) {
|
|
303
|
+
if (twitter.app.iphone) {
|
|
304
|
+
setTW("app:name:iphone", twitter.app.iphone.name);
|
|
305
|
+
setTW("app:id:iphone", twitter.app.iphone.id);
|
|
306
|
+
setTW("app:url:iphone", twitter.app.iphone.url);
|
|
307
|
+
}
|
|
308
|
+
if (twitter.app.ipad) {
|
|
309
|
+
setTW("app:name:ipad", twitter.app.ipad.name);
|
|
310
|
+
setTW("app:id:ipad", twitter.app.ipad.id);
|
|
311
|
+
setTW("app:url:ipad", twitter.app.ipad.url);
|
|
312
|
+
}
|
|
313
|
+
if (twitter.app.googleplay) {
|
|
314
|
+
setTW("app:name:googleplay", twitter.app.googleplay.name);
|
|
315
|
+
setTW("app:id:googleplay", twitter.app.googleplay.id);
|
|
316
|
+
setTW("app:url:googleplay", twitter.app.googleplay.url);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
// ============================================================================
|
|
321
|
+
// Main SEO Update Function
|
|
322
|
+
// ============================================================================
|
|
323
|
+
export const updateSEO = (options) => {
|
|
324
|
+
if (typeof document === "undefined")
|
|
325
|
+
return;
|
|
326
|
+
// Title with template support
|
|
327
|
+
if (options.title) {
|
|
328
|
+
const title = options.titleTemplate
|
|
329
|
+
? options.titleTemplate.replace("%s", options.title)
|
|
330
|
+
: options.title;
|
|
331
|
+
document.title = title;
|
|
332
|
+
}
|
|
333
|
+
// Language
|
|
334
|
+
if (options.lang) {
|
|
335
|
+
document.documentElement.lang = options.lang;
|
|
336
|
+
}
|
|
337
|
+
// Description
|
|
338
|
+
if (options.description) {
|
|
339
|
+
setMetaTag("name", "description", options.description);
|
|
340
|
+
}
|
|
341
|
+
// Canonical
|
|
342
|
+
if (options.canonical) {
|
|
343
|
+
setLinkTag({ rel: "canonical", href: options.canonical });
|
|
344
|
+
}
|
|
345
|
+
// Robots
|
|
346
|
+
if (options.robots !== undefined) {
|
|
347
|
+
// Handle both RobotsMeta and RobotsDirective[] types
|
|
348
|
+
if (Array.isArray(options.robots)) {
|
|
349
|
+
// Convert directive array to RobotsMeta object
|
|
350
|
+
const robotsMeta = {};
|
|
351
|
+
options.robots.forEach((directive) => {
|
|
352
|
+
switch (directive) {
|
|
353
|
+
case "index":
|
|
354
|
+
robotsMeta.index = true;
|
|
355
|
+
break;
|
|
356
|
+
case "noindex":
|
|
357
|
+
robotsMeta.index = false;
|
|
358
|
+
break;
|
|
359
|
+
case "follow":
|
|
360
|
+
robotsMeta.follow = true;
|
|
361
|
+
break;
|
|
362
|
+
case "nofollow":
|
|
363
|
+
robotsMeta.follow = false;
|
|
364
|
+
break;
|
|
365
|
+
case "noarchive":
|
|
366
|
+
robotsMeta.archive = false;
|
|
367
|
+
break;
|
|
368
|
+
case "nosnippet":
|
|
369
|
+
robotsMeta.snippet = false;
|
|
370
|
+
break;
|
|
371
|
+
case "notranslate":
|
|
372
|
+
robotsMeta.translate = false;
|
|
373
|
+
break;
|
|
374
|
+
case "noimageindex":
|
|
375
|
+
robotsMeta.imageIndex = false;
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
setRobotsMeta(robotsMeta);
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
setRobotsMeta(options.robots);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
// Viewport
|
|
386
|
+
if (options.viewport) {
|
|
387
|
+
setViewport(options.viewport);
|
|
388
|
+
}
|
|
389
|
+
// Theme Color
|
|
390
|
+
if (options.themeColor) {
|
|
391
|
+
setThemeColor(options.themeColor);
|
|
392
|
+
}
|
|
393
|
+
// Favicon
|
|
394
|
+
if (options.favicon) {
|
|
395
|
+
setFavicon(options.favicon);
|
|
396
|
+
}
|
|
397
|
+
if (options.appleTouchIcon) {
|
|
398
|
+
setAppleTouchIcon(options.appleTouchIcon);
|
|
399
|
+
}
|
|
400
|
+
if (options.maskIcon) {
|
|
401
|
+
setMaskIcon(options.maskIcon);
|
|
402
|
+
}
|
|
403
|
+
// Hreflang
|
|
404
|
+
if (options.hreflang && options.hreflang.length > 0) {
|
|
405
|
+
setHreflangTags(options.hreflang);
|
|
406
|
+
}
|
|
407
|
+
// Performance Hints
|
|
408
|
+
if (options.preload && options.preload.length > 0) {
|
|
409
|
+
setPreloadHints(options.preload);
|
|
410
|
+
}
|
|
411
|
+
if (options.preconnect && options.preconnect.length > 0) {
|
|
412
|
+
setPreconnectHints(options.preconnect);
|
|
413
|
+
}
|
|
414
|
+
if (options.dnsPrefetch && options.dnsPrefetch.length > 0) {
|
|
415
|
+
setDnsPrefetchHints(options.dnsPrefetch);
|
|
416
|
+
}
|
|
417
|
+
// Custom Meta Tags
|
|
418
|
+
if (options.meta && Array.isArray(options.meta)) {
|
|
419
|
+
options.meta.forEach((m) => {
|
|
420
|
+
if (m.name)
|
|
421
|
+
setMetaTag("name", m.name, m.content);
|
|
422
|
+
if (m.property)
|
|
423
|
+
setMetaTag("property", m.property, m.content);
|
|
424
|
+
if (m.httpEquiv)
|
|
425
|
+
setMetaTag("httpEquiv", m.httpEquiv, m.content);
|
|
426
|
+
if (m.charset)
|
|
427
|
+
setMetaTag("charset", m.charset);
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
// Custom Link Tags
|
|
431
|
+
if (options.link && Array.isArray(options.link)) {
|
|
432
|
+
options.link.forEach((link) => {
|
|
433
|
+
const attrs = { rel: link.rel, href: link.href };
|
|
434
|
+
if (link.type)
|
|
435
|
+
attrs.type = link.type;
|
|
436
|
+
if (link.sizes)
|
|
437
|
+
attrs.sizes = link.sizes;
|
|
438
|
+
if (link.media)
|
|
439
|
+
attrs.media = link.media;
|
|
440
|
+
if (link.crossOrigin)
|
|
441
|
+
attrs.crossorigin = link.crossOrigin;
|
|
442
|
+
if (link.as)
|
|
443
|
+
attrs.as = link.as;
|
|
444
|
+
setLinkTag(attrs);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
// Open Graph
|
|
448
|
+
setOpenGraph(options.openGraph);
|
|
449
|
+
// Twitter Card
|
|
450
|
+
setTwitterCard(options.twitter, options.openGraph);
|
|
451
|
+
// Additional Meta Tags (backward compatibility)
|
|
452
|
+
if (options.additionalMetaTags && Array.isArray(options.additionalMetaTags)) {
|
|
453
|
+
options.additionalMetaTags.forEach((m) => {
|
|
454
|
+
if (m.name)
|
|
455
|
+
setMetaTag("name", m.name, m.content);
|
|
456
|
+
if (m.property)
|
|
457
|
+
setMetaTag("property", m.property, m.content);
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
// Additional Link Tags (backward compatibility)
|
|
461
|
+
if (options.additionalLinkTags && Array.isArray(options.additionalLinkTags)) {
|
|
462
|
+
options.additionalLinkTags.forEach((link) => {
|
|
463
|
+
const attrs = { rel: link.rel, href: link.href };
|
|
464
|
+
if (link.type)
|
|
465
|
+
attrs.type = link.type;
|
|
466
|
+
if (link.sizes)
|
|
467
|
+
attrs.sizes = link.sizes;
|
|
468
|
+
if (link.media)
|
|
469
|
+
attrs.media = link.media;
|
|
470
|
+
if (link.crossOrigin)
|
|
471
|
+
attrs.crossorigin = link.crossOrigin;
|
|
472
|
+
if (link.as)
|
|
473
|
+
attrs.as = link.as;
|
|
474
|
+
setLinkTag(attrs);
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
// ============================================================================
|
|
479
|
+
// Utility Functions
|
|
480
|
+
// ============================================================================
|
|
481
|
+
/**
|
|
482
|
+
* Remove all SEO meta tags added by this library
|
|
483
|
+
*/
|
|
484
|
+
export const clearSEO = () => {
|
|
485
|
+
if (typeof document === "undefined")
|
|
486
|
+
return;
|
|
487
|
+
// Remove all meta tags with data-seo attribute
|
|
488
|
+
document.querySelectorAll('meta[data-seo="true"]').forEach((el) => el.remove());
|
|
489
|
+
// Remove all link tags with data-seo attribute
|
|
490
|
+
document.querySelectorAll('link[data-seo="true"]').forEach((el) => el.remove());
|
|
491
|
+
// Reset title
|
|
492
|
+
document.title = "";
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* Get current SEO state from DOM
|
|
496
|
+
*/
|
|
497
|
+
export const getCurrentSEOState = () => {
|
|
498
|
+
if (typeof document === "undefined")
|
|
499
|
+
return null;
|
|
500
|
+
const metaTags = [];
|
|
501
|
+
const linkTags = [];
|
|
502
|
+
// Get all meta tags
|
|
503
|
+
document.querySelectorAll("meta").forEach((meta) => {
|
|
504
|
+
const name = meta.getAttribute("name");
|
|
505
|
+
const property = meta.getAttribute("property");
|
|
506
|
+
const content = meta.getAttribute("content");
|
|
507
|
+
if (content) {
|
|
508
|
+
if (name) {
|
|
509
|
+
metaTags.push({ name, content });
|
|
510
|
+
}
|
|
511
|
+
else if (property) {
|
|
512
|
+
metaTags.push({ property, content });
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
// Get all link tags
|
|
517
|
+
document.querySelectorAll("link").forEach((link) => {
|
|
518
|
+
const rel = link.getAttribute("rel");
|
|
519
|
+
const href = link.getAttribute("href");
|
|
520
|
+
const type = link.getAttribute("type");
|
|
521
|
+
const sizes = link.getAttribute("sizes");
|
|
522
|
+
if (rel && href) {
|
|
523
|
+
linkTags.push({
|
|
524
|
+
rel,
|
|
525
|
+
href,
|
|
526
|
+
...(type && { type }),
|
|
527
|
+
...(sizes && { sizes }),
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
return {
|
|
532
|
+
title: document.title,
|
|
533
|
+
lang: document.documentElement.lang,
|
|
534
|
+
metaTags,
|
|
535
|
+
linkTags,
|
|
536
|
+
};
|
|
537
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema.org JSON-LD Generators
|
|
3
|
+
*
|
|
4
|
+
* Helper functions to generate valid Schema.org structured data
|
|
5
|
+
* for various content types like articles, products, organizations, etc.
|
|
6
|
+
*/
|
|
7
|
+
import type { ArticleJsonLd, ProductJsonLd, OrganizationJsonLd, LocalBusinessJsonLd, BreadcrumbJsonLd, FAQJsonLd, WebSiteJsonLd, PersonJsonLd, VideoJsonLd, SchemaGeneratorOptions } from "../types/schema.js";
|
|
8
|
+
export interface ArticleSchemaInput {
|
|
9
|
+
headline: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
image: string | string[];
|
|
12
|
+
datePublished: string;
|
|
13
|
+
dateModified?: string;
|
|
14
|
+
authorName: string;
|
|
15
|
+
authorUrl?: string;
|
|
16
|
+
authorType?: "Person" | "Organization";
|
|
17
|
+
publisherName: string;
|
|
18
|
+
publisherLogo: string;
|
|
19
|
+
publisherUrl?: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
articleSection?: string;
|
|
22
|
+
wordCount?: number;
|
|
23
|
+
keywords?: string | string[];
|
|
24
|
+
inLanguage?: string;
|
|
25
|
+
type?: "Article" | "NewsArticle" | "BlogPosting";
|
|
26
|
+
}
|
|
27
|
+
export declare const generateArticleSchema: (input: ArticleSchemaInput, options?: SchemaGeneratorOptions) => ArticleJsonLd;
|
|
28
|
+
export interface ProductSchemaInput {
|
|
29
|
+
name: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
image: string | string[];
|
|
32
|
+
price: number;
|
|
33
|
+
priceCurrency: string;
|
|
34
|
+
availability?: "InStock" | "OutOfStock" | "PreOrder";
|
|
35
|
+
url?: string;
|
|
36
|
+
brandName?: string;
|
|
37
|
+
sku?: string;
|
|
38
|
+
gtin?: string;
|
|
39
|
+
aggregateRating?: {
|
|
40
|
+
ratingValue: number;
|
|
41
|
+
reviewCount: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export declare const generateProductSchema: (input: ProductSchemaInput, options?: SchemaGeneratorOptions) => ProductJsonLd;
|
|
45
|
+
export interface OrganizationSchemaInput {
|
|
46
|
+
name: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
url?: string;
|
|
49
|
+
logo?: string;
|
|
50
|
+
sameAs?: string[];
|
|
51
|
+
contactPoint?: {
|
|
52
|
+
telephone: string;
|
|
53
|
+
contactType: string;
|
|
54
|
+
email?: string;
|
|
55
|
+
}[];
|
|
56
|
+
address?: {
|
|
57
|
+
streetAddress: string;
|
|
58
|
+
addressLocality: string;
|
|
59
|
+
addressRegion: string;
|
|
60
|
+
postalCode: string;
|
|
61
|
+
addressCountry: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export declare const generateOrganizationSchema: (input: OrganizationSchemaInput, options?: SchemaGeneratorOptions) => OrganizationJsonLd;
|
|
65
|
+
export interface LocalBusinessSchemaInput extends OrganizationSchemaInput {
|
|
66
|
+
address: {
|
|
67
|
+
streetAddress: string;
|
|
68
|
+
addressLocality: string;
|
|
69
|
+
addressRegion: string;
|
|
70
|
+
postalCode: string;
|
|
71
|
+
addressCountry: string;
|
|
72
|
+
};
|
|
73
|
+
geo?: {
|
|
74
|
+
latitude: number;
|
|
75
|
+
longitude: number;
|
|
76
|
+
};
|
|
77
|
+
openingHours?: {
|
|
78
|
+
dayOfWeek: string | string[];
|
|
79
|
+
opens: string;
|
|
80
|
+
closes: string;
|
|
81
|
+
}[];
|
|
82
|
+
priceRange?: string;
|
|
83
|
+
type?: "LocalBusiness" | "Restaurant" | "Store" | "Dentist" | "Hospital";
|
|
84
|
+
}
|
|
85
|
+
export declare const generateLocalBusinessSchema: (input: LocalBusinessSchemaInput, options?: SchemaGeneratorOptions) => LocalBusinessJsonLd;
|
|
86
|
+
export declare const generateBreadcrumbSchema: (items: Array<{
|
|
87
|
+
name: string;
|
|
88
|
+
item: string;
|
|
89
|
+
position?: number;
|
|
90
|
+
}>, options?: SchemaGeneratorOptions) => BreadcrumbJsonLd;
|
|
91
|
+
export interface FAQItemInput {
|
|
92
|
+
question: string;
|
|
93
|
+
answer: string;
|
|
94
|
+
}
|
|
95
|
+
export declare const generateFAQSchema: (faqs: FAQItemInput[], options?: SchemaGeneratorOptions) => FAQJsonLd;
|
|
96
|
+
export interface WebSiteSchemaInput {
|
|
97
|
+
name: string;
|
|
98
|
+
url: string;
|
|
99
|
+
description?: string;
|
|
100
|
+
searchTarget?: string;
|
|
101
|
+
searchQueryParam?: string;
|
|
102
|
+
publisher?: {
|
|
103
|
+
name: string;
|
|
104
|
+
logo?: string;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export declare const generateWebSiteSchema: (input: WebSiteSchemaInput, options?: SchemaGeneratorOptions) => WebSiteJsonLd;
|
|
108
|
+
export interface PersonSchemaInput {
|
|
109
|
+
name: string;
|
|
110
|
+
givenName?: string;
|
|
111
|
+
familyName?: string;
|
|
112
|
+
jobTitle?: string;
|
|
113
|
+
description?: string;
|
|
114
|
+
image?: string;
|
|
115
|
+
url?: string;
|
|
116
|
+
sameAs?: string[];
|
|
117
|
+
email?: string;
|
|
118
|
+
telephone?: string;
|
|
119
|
+
worksFor?: {
|
|
120
|
+
name: string;
|
|
121
|
+
url?: string;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export declare const generatePersonSchema: (input: PersonSchemaInput, options?: SchemaGeneratorOptions) => PersonJsonLd;
|
|
125
|
+
export interface VideoSchemaInput {
|
|
126
|
+
name: string;
|
|
127
|
+
description?: string;
|
|
128
|
+
thumbnailUrl: string;
|
|
129
|
+
uploadDate: string;
|
|
130
|
+
duration?: string;
|
|
131
|
+
embedUrl?: string;
|
|
132
|
+
viewCount?: number;
|
|
133
|
+
}
|
|
134
|
+
export declare const generateVideoSchema: (input: VideoSchemaInput, options?: SchemaGeneratorOptions) => VideoJsonLd;
|
|
135
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/utils/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,WAAW,EACX,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AA0B5B,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,M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