@umituz/web-seo 1.0.5 → 2.0.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/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/components/index.d.ts +8 -0
- package/dist/domains/seo/components/index.d.ts.map +1 -0
- package/dist/domains/seo/components/index.js +7 -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/index.d.ts +8 -0
- package/dist/domains/seo/hooks/index.d.ts.map +1 -0
- package/dist/domains/seo/hooks/index.js +7 -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 +194 -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 +24 -0
- package/dist/domains/seo/utils/dom.d.ts.map +1 -0
- package/dist/domains/seo/utils/dom.js +224 -0
- package/dist/domains/seo/utils/index.d.ts +10 -0
- package/dist/domains/seo/utils/index.d.ts.map +1 -0
- package/dist/domains/seo/utils/index.js +13 -0
- package/dist/domains/seo/utils/meta-tags/advanced.d.ts +31 -0
- package/dist/domains/seo/utils/meta-tags/advanced.d.ts.map +1 -0
- package/dist/domains/seo/utils/meta-tags/advanced.js +75 -0
- package/dist/domains/seo/utils/meta-tags/basic.d.ts +19 -0
- package/dist/domains/seo/utils/meta-tags/basic.d.ts.map +1 -0
- package/dist/domains/seo/utils/meta-tags/basic.js +93 -0
- package/dist/domains/seo/utils/meta-tags/index.d.ts +10 -0
- package/dist/domains/seo/utils/meta-tags/index.d.ts.map +1 -0
- package/dist/domains/seo/utils/meta-tags/index.js +9 -0
- package/dist/domains/seo/utils/meta-tags/performance.d.ts +19 -0
- package/dist/domains/seo/utils/meta-tags/performance.d.ts.map +1 -0
- package/dist/domains/seo/utils/meta-tags/performance.js +63 -0
- package/dist/domains/seo/utils/meta-tags/social.d.ts +15 -0
- package/dist/domains/seo/utils/meta-tags/social.d.ts.map +1 -0
- package/dist/domains/seo/utils/meta-tags/social.js +132 -0
- package/dist/domains/seo/utils/schema-generators/index.d.ts +7 -0
- package/dist/domains/seo/utils/schema-generators/index.d.ts.map +1 -0
- package/dist/domains/seo/utils/schema-generators/index.js +6 -0
- package/dist/domains/seo/utils/schema-generators/schema.d.ts +135 -0
- package/dist/domains/seo/utils/schema-generators/schema.d.ts.map +1 -0
- package/dist/domains/seo/utils/schema-generators/schema.js +321 -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/validation/index.d.ts +7 -0
- package/dist/domains/seo/utils/validation/index.d.ts.map +1 -0
- package/dist/domains/seo/utils/validation/index.js +6 -0
- package/dist/domains/seo/utils/validation/validators.d.ts +39 -0
- package/dist/domains/seo/utils/validation/validators.d.ts.map +1 -0
- package/dist/domains/seo/utils/validation/validators.js +364 -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/index.d.ts +8 -0
- package/dist/domains/seo/vite/index.d.ts.map +1 -0
- package/dist/domains/seo/vite/index.js +6 -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 +217 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/package.json +57 -7
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
import { useEffect, useCallback } from "react";
|
|
8
|
+
export const useJsonLd = (data, options) => {
|
|
9
|
+
const { strategy = "afterInteractive", id } = options || {};
|
|
10
|
+
const injectJsonLd = useCallback((jsonData) => {
|
|
11
|
+
if (typeof document === "undefined")
|
|
12
|
+
return;
|
|
13
|
+
const dataArray = Array.isArray(jsonData) ? jsonData : [jsonData];
|
|
14
|
+
dataArray.forEach((item, index) => {
|
|
15
|
+
// Remove existing script if present
|
|
16
|
+
const existingScript = document.querySelector(`script[type="application/ld+json"][data-seo-id="${id || JSON.stringify(item)}"]`);
|
|
17
|
+
if (existingScript) {
|
|
18
|
+
existingScript.remove();
|
|
19
|
+
}
|
|
20
|
+
// Create and inject new script
|
|
21
|
+
const script = document.createElement("script");
|
|
22
|
+
script.type = "application/ld+json";
|
|
23
|
+
script.textContent = JSON.stringify(item);
|
|
24
|
+
if (id) {
|
|
25
|
+
script.setAttribute("data-seo-id", `${id}-${index}`);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
script.setAttribute("data-seo-id", JSON.stringify(item));
|
|
29
|
+
}
|
|
30
|
+
script.setAttribute("data-seo-strategy", strategy);
|
|
31
|
+
document.head.appendChild(script);
|
|
32
|
+
});
|
|
33
|
+
}, [id, strategy]);
|
|
34
|
+
const removeJsonLd = useCallback(() => {
|
|
35
|
+
if (typeof document === "undefined")
|
|
36
|
+
return;
|
|
37
|
+
const scripts = document.querySelectorAll(`script[type="application/ld+json"][data-seo-id*="${id || ''}"]`);
|
|
38
|
+
scripts.forEach((script) => script.remove());
|
|
39
|
+
}, [id]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (data) {
|
|
42
|
+
injectJsonLd(data);
|
|
43
|
+
}
|
|
44
|
+
return () => {
|
|
45
|
+
removeJsonLd();
|
|
46
|
+
};
|
|
47
|
+
}, [data, injectJsonLd, removeJsonLd]);
|
|
48
|
+
return {
|
|
49
|
+
injectJsonLd,
|
|
50
|
+
removeJsonLd,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export default useJsonLd;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSEO.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/hooks/useSEO.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnD,eAAO,MAAM,MAAM,GAAI,SAAS,SAAS,SA6CxC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useEffect, useMemo } from "react";
|
|
2
|
+
import { updateSEO } from "../utils/dom.js";
|
|
3
|
+
export const useSEO = (options) => {
|
|
4
|
+
// Memoize dependencies for better performance
|
|
5
|
+
const dependencies = useMemo(() => [
|
|
6
|
+
options.title,
|
|
7
|
+
options.description,
|
|
8
|
+
options.lang,
|
|
9
|
+
options.canonical,
|
|
10
|
+
options.themeColor,
|
|
11
|
+
options.favicon,
|
|
12
|
+
JSON.stringify(options.meta),
|
|
13
|
+
JSON.stringify(options.link),
|
|
14
|
+
JSON.stringify(options.openGraph),
|
|
15
|
+
JSON.stringify(options.twitter),
|
|
16
|
+
JSON.stringify(options.jsonLd),
|
|
17
|
+
JSON.stringify(options.hreflang),
|
|
18
|
+
JSON.stringify(options.preload),
|
|
19
|
+
JSON.stringify(options.preconnect),
|
|
20
|
+
JSON.stringify(options.dnsPrefetch),
|
|
21
|
+
JSON.stringify(options.robots),
|
|
22
|
+
JSON.stringify(options.breadcrumbs),
|
|
23
|
+
options.viewport,
|
|
24
|
+
], [
|
|
25
|
+
options.title,
|
|
26
|
+
options.description,
|
|
27
|
+
options.lang,
|
|
28
|
+
options.canonical,
|
|
29
|
+
options.themeColor,
|
|
30
|
+
options.favicon,
|
|
31
|
+
options.meta,
|
|
32
|
+
options.link,
|
|
33
|
+
options.openGraph,
|
|
34
|
+
options.twitter,
|
|
35
|
+
options.jsonLd,
|
|
36
|
+
options.hreflang,
|
|
37
|
+
options.preload,
|
|
38
|
+
options.preconnect,
|
|
39
|
+
options.dnsPrefetch,
|
|
40
|
+
options.robots,
|
|
41
|
+
options.breadcrumbs,
|
|
42
|
+
options.viewport,
|
|
43
|
+
]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
updateSEO(options);
|
|
46
|
+
}, dependencies);
|
|
47
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { SEO } from "./components/SEO.js";
|
|
2
|
+
export { JsonLd } from "./components/JsonLd.js";
|
|
3
|
+
export { useSEO } from "./hooks/useSEO.js";
|
|
4
|
+
export { useJsonLd } from "./hooks/useJsonLd.js";
|
|
5
|
+
export { initSEO } from "./core/init.js";
|
|
6
|
+
export { updateSEO, clearSEO, getCurrentSEOState, } from "./utils/dom.js";
|
|
7
|
+
export { generateArticleSchema, generateProductSchema, generateOrganizationSchema, generateLocalBusinessSchema, generateBreadcrumbSchema, generateFAQSchema, generateWebSiteSchema, generatePersonSchema, generateVideoSchema, } from "./utils/schema.js";
|
|
8
|
+
export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry, truncateForSEO, generateSlug, } from "./utils/validators.js";
|
|
9
|
+
export { renderSEO, generateHead, extractSEOData, hydrateSEO, renderAsHelmet, } from "./ssr/renderer.js";
|
|
10
|
+
export { serializeSEO, deserializeSEO, serializeSEOToBase64, deserializeSEOFromBase64, compressSEO, serializeSEOToQueryString, deserializeSEOFromQueryString, safeDeserializeSEO, } from "./ssr/serializer.js";
|
|
11
|
+
export { viteSEOPlugin, quickSEOSetup, } from "./vite/plugin.js";
|
|
12
|
+
export type { ViteSEOPluginOptions } from "./vite/plugin.js";
|
|
13
|
+
export type { MetaTag, LinkTag, ScriptTag, SEOptions, SEOConfig, RobotsMeta, RobotsDirective, HreflangEntry, PreloadHint, PreconnectOrigin, DnsPrefetchDomain, ArticleMeta, ProductMeta, BreadcrumbItem, OpenGraphImage, SEOValidationResult, } from "./types/index.js";
|
|
14
|
+
export type { JsonLdTypes, ArticleJsonLd, ProductJsonLd, OrganizationJsonLd, LocalBusinessJsonLd, BreadcrumbJsonLd, FAQJsonLd, WebSiteJsonLd, PersonJsonLd, VideoJsonLd, SchemaType, SchemaGeneratorOptions, } from "./types/schema.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domains/seo/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,OAAO,EACL,SAAS,EACT,QAAQ,EACR,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,EAC3B,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,QAAQ,EACR,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACd,YAAY,GACb,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,UAAU,EACV,cAAc,GACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,WAAW,EACX,yBAAyB,EACzB,6BAA6B,EAC7B,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,aAAa,EACb,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG7D,YAAY,EAEV,OAAO,EACP,OAAO,EACP,SAAS,EACT,SAAS,EACT,SAAS,EAGT,UAAU,EACV,eAAe,EAGf,aAAa,EAGb,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EAGjB,WAAW,EACX,WAAW,EACX,cAAc,EAGd,cAAc,EAGd,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAEV,WAAW,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,EACV,sBAAsB,GACvB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// SEO Domain - Main Exports
|
|
3
|
+
// Domain-Driven Design structure for comprehensive SEO functionality
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Components
|
|
6
|
+
export { SEO } from "./components/SEO.js";
|
|
7
|
+
export { JsonLd } from "./components/JsonLd.js";
|
|
8
|
+
// Hooks
|
|
9
|
+
export { useSEO } from "./hooks/useSEO.js";
|
|
10
|
+
export { useJsonLd } from "./hooks/useJsonLd.js";
|
|
11
|
+
// Core
|
|
12
|
+
export { initSEO } from "./core/init.js";
|
|
13
|
+
// Utils
|
|
14
|
+
export { updateSEO, clearSEO, getCurrentSEOState, } from "./utils/dom.js";
|
|
15
|
+
export { generateArticleSchema, generateProductSchema, generateOrganizationSchema, generateLocalBusinessSchema, generateBreadcrumbSchema, generateFAQSchema, generateWebSiteSchema, generatePersonSchema, generateVideoSchema, } from "./utils/schema.js";
|
|
16
|
+
export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry, truncateForSEO, generateSlug, } from "./utils/validators.js";
|
|
17
|
+
// SSR
|
|
18
|
+
export { renderSEO, generateHead, extractSEOData, hydrateSEO, renderAsHelmet, } from "./ssr/renderer.js";
|
|
19
|
+
export { serializeSEO, deserializeSEO, serializeSEOToBase64, deserializeSEOFromBase64, compressSEO, serializeSEOToQueryString, deserializeSEOFromQueryString, safeDeserializeSEO, } from "./ssr/serializer.js";
|
|
20
|
+
// Vite Plugin
|
|
21
|
+
export { viteSEOPlugin, quickSEOSetup, } from "./vite/plugin.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEO SSR Renderer
|
|
3
|
+
*
|
|
4
|
+
* Server-side rendering utilities for SEO.
|
|
5
|
+
* Generates HTML strings for meta tags and structured data.
|
|
6
|
+
*/
|
|
7
|
+
import type { SEOptions } from "../types/index.js";
|
|
8
|
+
export interface RenderedSEO {
|
|
9
|
+
/** Title tag */
|
|
10
|
+
title: string;
|
|
11
|
+
/** All meta tags as HTML */
|
|
12
|
+
meta: string;
|
|
13
|
+
/** All link tags as HTML */
|
|
14
|
+
link: string;
|
|
15
|
+
/** All JSON-LD scripts as HTML */
|
|
16
|
+
jsonLd: string;
|
|
17
|
+
/** Complete HTML head content */
|
|
18
|
+
toHTML(): string;
|
|
19
|
+
/** Convert to string (same as toHTML) */
|
|
20
|
+
toString(): string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Render SEO options to HTML strings for server-side rendering
|
|
24
|
+
*/
|
|
25
|
+
export declare const renderSEO: (options: SEOptions) => RenderedSEO;
|
|
26
|
+
/**
|
|
27
|
+
* Generate complete HTML head with SEO tags
|
|
28
|
+
*/
|
|
29
|
+
export declare const generateHead: (options: SEOptions) => string;
|
|
30
|
+
/**
|
|
31
|
+
* Extract SEO data for hydration
|
|
32
|
+
*/
|
|
33
|
+
export declare const extractSEOData: (options: SEOptions) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Hydrate SEO on client side
|
|
36
|
+
*/
|
|
37
|
+
export declare const hydrateSEO: (serializedData: string) => void;
|
|
38
|
+
export interface RenderedMetaTag {
|
|
39
|
+
toString(): string;
|
|
40
|
+
toComponent(): unknown;
|
|
41
|
+
}
|
|
42
|
+
export interface HelmetData {
|
|
43
|
+
base: RenderedMetaTag[];
|
|
44
|
+
bodyAttributes: Record<string, string>;
|
|
45
|
+
htmlAttributes: Record<string, string>;
|
|
46
|
+
link: RenderedMetaTag[];
|
|
47
|
+
meta: RenderedMetaTag[];
|
|
48
|
+
noscript: RenderedMetaTag[];
|
|
49
|
+
script: RenderedMetaTag[];
|
|
50
|
+
style: RenderedMetaTag[];
|
|
51
|
+
title: string;
|
|
52
|
+
titleAttributes: Record<string, string>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Render SEO in Helmet-compatible format
|
|
56
|
+
*/
|
|
57
|
+
export declare const renderAsHelmet: (options: SEOptions) => HelmetData;
|
|
58
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/ssr/renderer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAMnD,MAAM,WAAW,WAAW;IAC1B,gBAAgB;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,MAAM,IAAI,MAAM,CAAC;IACjB,yCAAyC;IACzC,QAAQ,IAAI,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,SAAS,SAAS,KAAG,WA4K9C,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,SAAS,KAAG,MAKjD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,KAAG,MAEnD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,gBAAgB,MAAM,KAAG,IASnD,CAAC;AAMF,MAAM,WAAW,eAAe;IAC9B,QAAQ,IAAI,MAAM,CAAC;IACnB,WAAW,IAAI,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,KAAG,UAenD,CAAC"}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEO SSR Renderer
|
|
3
|
+
*
|
|
4
|
+
* Server-side rendering utilities for SEO.
|
|
5
|
+
* Generates HTML strings for meta tags and structured data.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Render SEO options to HTML strings for server-side rendering
|
|
9
|
+
*/
|
|
10
|
+
export const renderSEO = (options) => {
|
|
11
|
+
const metaTags = [];
|
|
12
|
+
const linkTags = [];
|
|
13
|
+
const jsonLdScripts = [];
|
|
14
|
+
// Title
|
|
15
|
+
const title = options.titleTemplate
|
|
16
|
+
? options.titleTemplate.replace("%s", options.title || "")
|
|
17
|
+
: options.title || "";
|
|
18
|
+
// Charset
|
|
19
|
+
metaTags.push('<meta charset="utf-8" />');
|
|
20
|
+
metaTags.push('<meta name="viewport" content="width=device-width, initial-scale=1" />');
|
|
21
|
+
// Description
|
|
22
|
+
if (options.description) {
|
|
23
|
+
metaTags.push(`<meta name="description" content="${options.description}" />`);
|
|
24
|
+
}
|
|
25
|
+
// Robots
|
|
26
|
+
if (options.robots !== undefined) {
|
|
27
|
+
let robotsContent = "";
|
|
28
|
+
if (typeof options.robots === "boolean") {
|
|
29
|
+
robotsContent = options.robots ? "index, follow" : "noindex, nofollow";
|
|
30
|
+
}
|
|
31
|
+
else if (Array.isArray(options.robots)) {
|
|
32
|
+
robotsContent = options.robots.join(", ");
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const directives = [];
|
|
36
|
+
if (options.robots.index !== undefined)
|
|
37
|
+
directives.push(options.robots.index ? "index" : "noindex");
|
|
38
|
+
if (options.robots.follow !== undefined)
|
|
39
|
+
directives.push(options.robots.follow ? "follow" : "nofollow");
|
|
40
|
+
if (options.robots.archive !== undefined)
|
|
41
|
+
directives.push(options.robots.archive ? "all" : "noarchive");
|
|
42
|
+
if (options.robots.snippet !== undefined)
|
|
43
|
+
directives.push(options.robots.snippet ? "all" : "nosnippet");
|
|
44
|
+
robotsContent = directives.join(", ");
|
|
45
|
+
}
|
|
46
|
+
metaTags.push(`<meta name="robots" content="${robotsContent}" />`);
|
|
47
|
+
}
|
|
48
|
+
// Canonical
|
|
49
|
+
if (options.canonical) {
|
|
50
|
+
linkTags.push(`<link rel="canonical" href="${options.canonical}" />`);
|
|
51
|
+
}
|
|
52
|
+
// Theme color
|
|
53
|
+
if (options.themeColor) {
|
|
54
|
+
metaTags.push(`<meta name="theme-color" content="${options.themeColor}" />`);
|
|
55
|
+
}
|
|
56
|
+
// Favicon
|
|
57
|
+
if (options.favicon) {
|
|
58
|
+
linkTags.push(`<link rel="icon" type="image/x-icon" href="${options.favicon}" />`);
|
|
59
|
+
}
|
|
60
|
+
if (options.appleTouchIcon) {
|
|
61
|
+
linkTags.push(`<link rel="apple-touch-icon" sizes="180x180" href="${options.appleTouchIcon}" />`);
|
|
62
|
+
}
|
|
63
|
+
if (options.maskIcon) {
|
|
64
|
+
linkTags.push(`<link rel="mask-icon" href="${options.maskIcon}" />`);
|
|
65
|
+
}
|
|
66
|
+
// Hreflang
|
|
67
|
+
if (options.hreflang && options.hreflang.length > 0) {
|
|
68
|
+
options.hreflang.forEach((entry) => {
|
|
69
|
+
linkTags.push(`<link rel="alternate" hreflang="${entry.lang}" href="${entry.url}" />`);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Preload
|
|
73
|
+
if (options.preload && options.preload.length > 0) {
|
|
74
|
+
options.preload.forEach((preload) => {
|
|
75
|
+
const attrs = [`rel="preload"`, `href="${preload.href}"`, `as="${preload.as}"`];
|
|
76
|
+
if (preload.type)
|
|
77
|
+
attrs.push(`type="${preload.type}"`);
|
|
78
|
+
if (preload.crossOrigin)
|
|
79
|
+
attrs.push(`crossorigin="${preload.crossOrigin}"`);
|
|
80
|
+
if (preload.integrity)
|
|
81
|
+
attrs.push(`integrity="${preload.integrity}"`);
|
|
82
|
+
linkTags.push(`<link ${attrs.join(" ")} />`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// Preconnect
|
|
86
|
+
if (options.preconnect && options.preconnect.length > 0) {
|
|
87
|
+
options.preconnect.forEach((origin) => {
|
|
88
|
+
const attrs = [`rel="preconnect"`, `href="${origin.href}"`];
|
|
89
|
+
if (origin.crossOrigin)
|
|
90
|
+
attrs.push(`crossorigin="${origin.crossOrigin}"`);
|
|
91
|
+
linkTags.push(`<link ${attrs.join(" ")} />`);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// DNS Prefetch
|
|
95
|
+
if (options.dnsPrefetch && options.dnsPrefetch.length > 0) {
|
|
96
|
+
options.dnsPrefetch.forEach((domain) => {
|
|
97
|
+
linkTags.push(`<link rel="dns-prefetch" href="${domain.href}" />`);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// Custom meta tags
|
|
101
|
+
if (options.meta && options.meta.length > 0) {
|
|
102
|
+
options.meta.forEach((m) => {
|
|
103
|
+
if (m.name) {
|
|
104
|
+
metaTags.push(`<meta name="${m.name}" content="${m.content}" />`);
|
|
105
|
+
}
|
|
106
|
+
if (m.property) {
|
|
107
|
+
metaTags.push(`<meta property="${m.property}" content="${m.content}" />`);
|
|
108
|
+
}
|
|
109
|
+
if (m.httpEquiv) {
|
|
110
|
+
metaTags.push(`<meta http-equiv="${m.httpEquiv}" content="${m.content}" />`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// Custom link tags
|
|
115
|
+
if (options.link && options.link.length > 0) {
|
|
116
|
+
options.link.forEach((link) => {
|
|
117
|
+
const attrs = [`rel="${link.rel}"`, `href="${link.href}"`];
|
|
118
|
+
if (link.type)
|
|
119
|
+
attrs.push(`type="${link.type}"`);
|
|
120
|
+
if (link.sizes)
|
|
121
|
+
attrs.push(`sizes="${link.sizes}"`);
|
|
122
|
+
if (link.media)
|
|
123
|
+
attrs.push(`media="${link.media}"`);
|
|
124
|
+
if (link.crossOrigin)
|
|
125
|
+
attrs.push(`crossorigin="${link.crossOrigin}"`);
|
|
126
|
+
if (link.as)
|
|
127
|
+
attrs.push(`as="${link.as}"`);
|
|
128
|
+
linkTags.push(`<link ${attrs.join(" ")} />`);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// Open Graph
|
|
132
|
+
if (options.openGraph) {
|
|
133
|
+
if (options.openGraph.title)
|
|
134
|
+
metaTags.push(`<meta property="og:title" content="${options.openGraph.title}" />`);
|
|
135
|
+
if (options.openGraph.description)
|
|
136
|
+
metaTags.push(`<meta property="og:description" content="${options.openGraph.description}" />`);
|
|
137
|
+
if (options.openGraph.url)
|
|
138
|
+
metaTags.push(`<meta property="og:url" content="${options.openGraph.url}" />`);
|
|
139
|
+
if (options.openGraph.type)
|
|
140
|
+
metaTags.push(`<meta property="og:type" content="${options.openGraph.type}" />`);
|
|
141
|
+
if (options.openGraph.siteName)
|
|
142
|
+
metaTags.push(`<meta property="og:site_name" content="${options.openGraph.siteName}" />`);
|
|
143
|
+
if (options.openGraph.locale)
|
|
144
|
+
metaTags.push(`<meta property="og:locale" content="${options.openGraph.locale}" />`);
|
|
145
|
+
// Images
|
|
146
|
+
if (options.openGraph.image) {
|
|
147
|
+
if (Array.isArray(options.openGraph.image)) {
|
|
148
|
+
options.openGraph.image.forEach((img) => {
|
|
149
|
+
metaTags.push(`<meta property="og:image" content="${img.url}" />`);
|
|
150
|
+
if (img.alt)
|
|
151
|
+
metaTags.push(`<meta property="og:image:alt" content="${img.alt}" />`);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
metaTags.push(`<meta property="og:image" content="${options.openGraph.image}" />`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Twitter Card
|
|
160
|
+
if (options.twitter) {
|
|
161
|
+
if (options.twitter.cardType)
|
|
162
|
+
metaTags.push(`<meta name="twitter:card" content="${options.twitter.cardType}" />`);
|
|
163
|
+
if (options.twitter.site)
|
|
164
|
+
metaTags.push(`<meta name="twitter:site" content="${options.twitter.site}" />`);
|
|
165
|
+
if (options.twitter.handle)
|
|
166
|
+
metaTags.push(`<meta name="twitter:creator" content="${options.twitter.handle}" />`);
|
|
167
|
+
if (options.twitter.title)
|
|
168
|
+
metaTags.push(`<meta name="twitter:title" content="${options.twitter.title}" />`);
|
|
169
|
+
if (options.twitter.description)
|
|
170
|
+
metaTags.push(`<meta name="twitter:description" content="${options.twitter.description}" />`);
|
|
171
|
+
if (options.twitter.image)
|
|
172
|
+
metaTags.push(`<meta name="twitter:image" content="${options.twitter.image}" />`);
|
|
173
|
+
if (options.twitter.imageAlt)
|
|
174
|
+
metaTags.push(`<meta name="twitter:image:alt" content="${options.twitter.imageAlt}" />`);
|
|
175
|
+
}
|
|
176
|
+
// JSON-LD
|
|
177
|
+
if (options.jsonLd && options.jsonLd.length > 0) {
|
|
178
|
+
options.jsonLd.forEach((data) => {
|
|
179
|
+
jsonLdScripts.push(`<script type="application/ld+json">${JSON.stringify(data)}</script>`);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
title,
|
|
184
|
+
meta: metaTags.join("\n "),
|
|
185
|
+
link: linkTags.join("\n "),
|
|
186
|
+
jsonLd: jsonLdScripts.join("\n "),
|
|
187
|
+
toHTML() {
|
|
188
|
+
return ` <title>${this.title}</title>\n${this.meta ? ` ${this.meta}\n` : ""}${this.link ? ` ${this.link}\n` : ""}${this.jsonLd ? ` ${this.jsonLd}\n` : ""}`;
|
|
189
|
+
},
|
|
190
|
+
toString() {
|
|
191
|
+
return this.toHTML();
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
// ============================================================================
|
|
196
|
+
// SSR SEO Utilities
|
|
197
|
+
// ============================================================================
|
|
198
|
+
/**
|
|
199
|
+
* Generate complete HTML head with SEO tags
|
|
200
|
+
*/
|
|
201
|
+
export const generateHead = (options) => {
|
|
202
|
+
const rendered = renderSEO(options);
|
|
203
|
+
return ` <head${options.lang ? ` lang="${options.lang}"` : ""}>
|
|
204
|
+
${rendered.toHTML().split("\n").map(line => ` ${line}`).join("\n")}
|
|
205
|
+
</head>`;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Extract SEO data for hydration
|
|
209
|
+
*/
|
|
210
|
+
export const extractSEOData = (options) => {
|
|
211
|
+
return JSON.stringify(options);
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Hydrate SEO on client side
|
|
215
|
+
*/
|
|
216
|
+
export const hydrateSEO = (serializedData) => {
|
|
217
|
+
if (typeof window === "undefined")
|
|
218
|
+
return;
|
|
219
|
+
const options = JSON.parse(serializedData);
|
|
220
|
+
// Import updateSEO dynamically to avoid circular dependencies
|
|
221
|
+
import("../utils/dom.js").then(({ updateSEO }) => {
|
|
222
|
+
updateSEO(options);
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Render SEO in Helmet-compatible format
|
|
227
|
+
*/
|
|
228
|
+
export const renderAsHelmet = (options) => {
|
|
229
|
+
const rendered = renderSEO(options);
|
|
230
|
+
return {
|
|
231
|
+
base: [],
|
|
232
|
+
bodyAttributes: {},
|
|
233
|
+
htmlAttributes: options.lang ? { lang: options.lang } : {},
|
|
234
|
+
link: [],
|
|
235
|
+
meta: [],
|
|
236
|
+
noscript: [],
|
|
237
|
+
script: [],
|
|
238
|
+
style: [],
|
|
239
|
+
title: rendered.title,
|
|
240
|
+
titleAttributes: {},
|
|
241
|
+
};
|
|
242
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEO Serializer
|
|
3
|
+
*
|
|
4
|
+
* Serialization utilities for SEO data.
|
|
5
|
+
* Used for server-side rendering and hydration.
|
|
6
|
+
*/
|
|
7
|
+
import type { SEOptions } from "../types/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Serialize SEO options to a string for transmission/hydration
|
|
10
|
+
*/
|
|
11
|
+
export declare const serializeSEO: (options: SEOptions) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Deserialize SEO options from a string
|
|
14
|
+
*/
|
|
15
|
+
export declare const deserializeSEO: (data: string) => SEOptions;
|
|
16
|
+
/**
|
|
17
|
+
* Serialize SEO options to base64 for safe URL transmission
|
|
18
|
+
*/
|
|
19
|
+
export declare const serializeSEOToBase64: (options: SEOptions) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Deserialize SEO options from base64
|
|
22
|
+
*/
|
|
23
|
+
export declare const deserializeSEOFromBase64: (base64: string) => SEOptions;
|
|
24
|
+
interface SEOState {
|
|
25
|
+
options: SEOptions;
|
|
26
|
+
timestamp: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create SEO state with timestamp
|
|
30
|
+
*/
|
|
31
|
+
export declare const createSEOState: (options: SEOptions) => SEOState;
|
|
32
|
+
/**
|
|
33
|
+
* Serialize SEO state
|
|
34
|
+
*/
|
|
35
|
+
export declare const serializeSEOState: (state: SEOState) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Deserialize SEO state
|
|
38
|
+
*/
|
|
39
|
+
export declare const deserializeSEOState: (data: string) => SEOState;
|
|
40
|
+
/**
|
|
41
|
+
* Check if SEO state is stale (older than specified milliseconds)
|
|
42
|
+
*/
|
|
43
|
+
export declare const isSEOStateStale: (state: SEOState, maxAge?: number) => boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Compress SEO options using simple compression
|
|
46
|
+
* Removes undefined values and empty arrays
|
|
47
|
+
*/
|
|
48
|
+
export declare const compressSEO: (options: SEOptions) => SEOptions;
|
|
49
|
+
/**
|
|
50
|
+
* Decompress SEO options (identity function, kept for API consistency)
|
|
51
|
+
*/
|
|
52
|
+
export declare const decompressSEO: (options: SEOptions) => SEOptions;
|
|
53
|
+
/**
|
|
54
|
+
* Serialize SEO options to URL-safe query string
|
|
55
|
+
* Only includes essential SEO data for social sharing previews
|
|
56
|
+
*/
|
|
57
|
+
export declare const serializeSEOToQueryString: (options: SEOptions) => string;
|
|
58
|
+
/**
|
|
59
|
+
* Deserialize SEO options from query string
|
|
60
|
+
*/
|
|
61
|
+
export declare const deserializeSEOFromQueryString: (queryString: string) => Partial<SEOptions>;
|
|
62
|
+
/**
|
|
63
|
+
* Validate serialized SEO data before deserialization
|
|
64
|
+
*/
|
|
65
|
+
export declare const validateSerializedSEO: (data: string) => boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Safe deserialize with validation
|
|
68
|
+
*/
|
|
69
|
+
export declare const safeDeserializeSEO: (data: string) => SEOptions | null;
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../../../src/domains/seo/ssr/serializer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAMnD;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,SAAS,KAAG,MAEjD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,SAE7C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,SAAS,KAAG,MAOzD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,QAAQ,MAAM,KAAG,SASzD,CAAC;AAMF,UAAU,QAAQ;IAChB,OAAO,EAAE,SAAS,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,SAAS,KAAG,QAKnD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,QAAQ,KAAG,MAEnD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,QAElD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,QAAQ,EAAE,SAAQ,MAAgB,KAAG,OAE3E,CAAC;AAMF;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,SAAS,SAAS,KAAG,SAoBhD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,SAAS,KAAG,SAElD,CAAC;AAMF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,SAAS,KAAG,MAa9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,6BAA6B,GAAI,aAAa,MAAM,KAAG,OAAO,CAAC,SAAS,CAapF,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,MAAM,MAAM,KAAG,OAOpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,SAAS,GAAG,IAY7D,CAAC"}
|