@umituz/web-seo 2.0.21 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/domains/seo/components/JsonLd.d.ts +7 -6
- package/dist/domains/seo/components/JsonLd.js +26 -77
- package/dist/domains/seo/components/SEO.d.ts +7 -0
- package/dist/domains/seo/components/SEO.js +10 -33
- package/dist/domains/seo/core/constants.d.ts +15 -0
- package/dist/domains/seo/core/constants.js +15 -0
- package/dist/domains/seo/core/deep-equal.d.ts +8 -0
- package/dist/domains/seo/core/deep-equal.js +28 -0
- package/dist/domains/seo/core/dom-queue.d.ts +10 -0
- package/dist/domains/seo/core/dom-queue.js +37 -0
- package/dist/domains/seo/core/escape.d.ts +12 -0
- package/dist/domains/seo/core/escape.js +41 -0
- package/dist/domains/seo/core/hash.d.ts +9 -0
- package/dist/domains/seo/core/hash.js +29 -0
- package/dist/domains/seo/core/init.d.ts +15 -2
- package/dist/domains/seo/core/init.js +38 -18
- package/dist/domains/seo/core/seo-strategies.d.ts +29 -0
- package/dist/domains/seo/core/seo-strategies.js +694 -0
- package/dist/domains/seo/core/seo-strategy.d.ts +37 -0
- package/dist/domains/seo/core/seo-strategy.js +14 -0
- package/dist/domains/seo/hooks/useJsonLd.d.ts +6 -7
- package/dist/domains/seo/hooks/useJsonLd.js +27 -61
- package/dist/domains/seo/hooks/useSEO.d.ts +6 -0
- package/dist/domains/seo/hooks/useSEO.js +7 -29
- package/dist/domains/seo/ssr/helmet.d.ts +25 -0
- package/dist/domains/seo/ssr/helmet.js +23 -0
- package/dist/domains/seo/ssr/index.d.ts +10 -0
- package/dist/domains/seo/ssr/index.js +8 -0
- package/dist/domains/seo/ssr/renderer.d.ts +11 -36
- package/dist/domains/seo/ssr/renderer.js +51 -285
- package/dist/domains/seo/ssr/serializer.d.ts +5 -60
- package/dist/domains/seo/ssr/serializer.js +26 -166
- package/dist/domains/seo/types/index.d.ts +0 -4
- package/dist/domains/seo/types/schema.d.ts +22 -1
- package/dist/domains/seo/utils/dom/dom-context.d.ts +13 -0
- package/dist/domains/seo/utils/dom/dom-context.js +62 -0
- package/dist/domains/seo/utils/dom/dom-mutator.d.ts +31 -0
- package/dist/domains/seo/utils/dom/dom-mutator.js +89 -0
- package/dist/domains/seo/utils/dom/index.d.ts +1 -0
- package/dist/domains/seo/utils/dom/index.js +1 -0
- package/dist/domains/seo/utils/index.d.ts +3 -4
- package/dist/domains/seo/utils/index.js +3 -5
- package/dist/domains/seo/utils/schema-generators/base.d.ts +25 -0
- package/dist/domains/seo/utils/schema-generators/base.js +50 -0
- package/dist/domains/seo/utils/schema-generators/factory.d.ts +27 -0
- package/dist/domains/seo/utils/schema-generators/factory.js +49 -0
- package/dist/domains/seo/utils/schema-generators/generators/article.d.ts +4 -0
- package/dist/domains/seo/utils/schema-generators/generators/article.js +39 -0
- package/dist/domains/seo/utils/schema-generators/generators/breadcrumb.d.ts +6 -0
- package/dist/domains/seo/utils/schema-generators/generators/breadcrumb.js +18 -0
- package/dist/domains/seo/utils/schema-generators/generators/course.d.ts +3 -0
- package/dist/domains/seo/utils/schema-generators/generators/course.js +70 -0
- package/dist/domains/seo/utils/schema-generators/generators/faq.d.ts +3 -0
- package/dist/domains/seo/utils/schema-generators/generators/faq.js +21 -0
- package/dist/domains/seo/utils/schema-generators/generators/local-business.d.ts +3 -0
- package/dist/domains/seo/utils/schema-generators/generators/local-business.js +45 -0
- package/dist/domains/seo/utils/schema-generators/generators/organization.d.ts +3 -0
- package/dist/domains/seo/utils/schema-generators/generators/organization.js +25 -0
- package/dist/domains/seo/utils/schema-generators/generators/person.d.ts +3 -0
- package/dist/domains/seo/utils/schema-generators/generators/person.js +27 -0
- package/dist/domains/seo/utils/schema-generators/generators/product.d.ts +3 -0
- package/dist/domains/seo/utils/schema-generators/generators/product.js +40 -0
- package/dist/domains/seo/utils/schema-generators/generators/video.d.ts +3 -0
- package/dist/domains/seo/utils/schema-generators/generators/video.js +23 -0
- package/dist/domains/seo/utils/schema-generators/generators/website.d.ts +3 -0
- package/dist/domains/seo/utils/schema-generators/generators/website.js +30 -0
- package/dist/domains/seo/utils/schema-generators/index.d.ts +15 -2
- package/dist/domains/seo/utils/schema-generators/index.js +13 -2
- package/dist/domains/seo/utils/schema-generators/types.d.ts +142 -0
- package/dist/domains/seo/utils/schema-generators/types.js +5 -0
- package/dist/domains/seo/utils/validation/hreflang-validator.d.ts +7 -0
- package/dist/domains/seo/utils/validation/hreflang-validator.js +13 -0
- package/dist/domains/seo/utils/validation/image-validator.d.ts +7 -0
- package/dist/domains/seo/utils/validation/image-validator.js +24 -0
- package/dist/domains/seo/utils/validation/index.d.ts +10 -2
- package/dist/domains/seo/utils/validation/index.js +10 -2
- package/dist/domains/seo/utils/validation/jsonld-validator.d.ts +9 -0
- package/dist/domains/seo/utils/validation/jsonld-validator.js +74 -0
- package/dist/domains/seo/utils/validation/language-code.d.ts +7 -0
- package/dist/domains/seo/utils/validation/language-code.js +8 -0
- package/dist/domains/seo/utils/validation/length-validator.d.ts +10 -0
- package/dist/domains/seo/utils/validation/length-validator.js +40 -0
- package/dist/domains/seo/utils/validation/seo-auditor.d.ts +17 -0
- package/dist/domains/seo/utils/validation/seo-auditor.js +144 -0
- package/dist/domains/seo/utils/validation/text-helpers.d.ts +7 -0
- package/dist/domains/seo/utils/validation/text-helpers.js +12 -0
- package/dist/domains/seo/utils/validation/url-validator.d.ts +8 -0
- package/dist/domains/seo/utils/validation/url-validator.js +26 -0
- package/dist/domains/seo/vite/index.d.ts +6 -4
- package/dist/domains/seo/vite/index.js +5 -3
- package/dist/domains/seo/vite/plugin.d.ts +3 -55
- package/dist/domains/seo/vite/plugin.js +28 -186
- package/dist/domains/seo/vite/presets.d.ts +14 -0
- package/dist/domains/seo/vite/presets.js +33 -0
- package/dist/domains/seo/vite/robots-generator.d.ts +9 -0
- package/dist/domains/seo/vite/robots-generator.js +36 -0
- package/dist/domains/seo/vite/sitemap-generator.d.ts +15 -0
- package/dist/domains/seo/vite/sitemap-generator.js +56 -0
- package/dist/domains/seo/vite/types.d.ts +29 -0
- package/dist/domains/seo/vite/types.js +4 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.js +7 -6
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEO rendering strategies.
|
|
3
|
+
*
|
|
4
|
+
* A strategy encapsulates one piece of SEO output (title, robots, OG tags,
|
|
5
|
+
* hreflang, etc.). The same strategy is consumed by:
|
|
6
|
+
* - `dom/dom-mutator.ts` – applies the change to the live DOM
|
|
7
|
+
* - `ssr/renderer.ts` – serializes the change to an HTML string
|
|
8
|
+
*
|
|
9
|
+
* This is the Strategy pattern: a list of small, focused objects, each
|
|
10
|
+
* responsible for one concern, dispatched by a single orchestrator. It
|
|
11
|
+
* eliminates the historical bug where SSR and the DOM output diverged
|
|
12
|
+
* (e.g. SSR dropped OG image width/height/type).
|
|
13
|
+
*/
|
|
14
|
+
import type { SEOptions } from "../types/index.js";
|
|
15
|
+
/** Output for the DOM: a side-effect applied to `document.head`. */
|
|
16
|
+
export interface DOMContext {
|
|
17
|
+
/** Apply or update a `<meta>` tag. `undefined` content is a no-op. */
|
|
18
|
+
setMeta: (name: string, content: string | undefined) => void;
|
|
19
|
+
/** Apply or update a `<link>` tag. */
|
|
20
|
+
setLink: (attrs: Record<string, string>) => void;
|
|
21
|
+
}
|
|
22
|
+
/** Output for SSR: a builder that collects tags as HTML strings. */
|
|
23
|
+
export interface HTMLContext {
|
|
24
|
+
meta: string[];
|
|
25
|
+
link: string[];
|
|
26
|
+
jsonLd: string[];
|
|
27
|
+
}
|
|
28
|
+
export interface Strategy {
|
|
29
|
+
/** Stable key, useful for debugging and tests. */
|
|
30
|
+
readonly id: string;
|
|
31
|
+
/** Returns true when the strategy has work to do for these options. */
|
|
32
|
+
applies(options: SEOptions): boolean;
|
|
33
|
+
/** Apply to the live DOM. */
|
|
34
|
+
applyDOM(options: SEOptions, ctx: DOMContext): void;
|
|
35
|
+
/** Append HTML strings to the SSR context. */
|
|
36
|
+
applyHTML(options: SEOptions, ctx: HTMLContext): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEO rendering strategies.
|
|
3
|
+
*
|
|
4
|
+
* A strategy encapsulates one piece of SEO output (title, robots, OG tags,
|
|
5
|
+
* hreflang, etc.). The same strategy is consumed by:
|
|
6
|
+
* - `dom/dom-mutator.ts` – applies the change to the live DOM
|
|
7
|
+
* - `ssr/renderer.ts` – serializes the change to an HTML string
|
|
8
|
+
*
|
|
9
|
+
* This is the Strategy pattern: a list of small, focused objects, each
|
|
10
|
+
* responsible for one concern, dispatched by a single orchestrator. It
|
|
11
|
+
* eliminates the historical bug where SSR and the DOM output diverged
|
|
12
|
+
* (e.g. SSR dropped OG image width/height/type).
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useJsonLd
|
|
2
|
+
* `useJsonLd(data, options?)` hook.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Programmatic JSON-LD injection. Returns `inject`/`remove` callbacks
|
|
5
|
+
* so the caller can re-fire the injection on demand (e.g. after a route
|
|
6
|
+
* transition) or clean up manually.
|
|
6
7
|
*/
|
|
7
8
|
import type { JsonLdTypes } from "../types/schema.js";
|
|
8
9
|
interface UseJsonLdOptions {
|
|
9
|
-
/** Strategy for when to inject the script tag */
|
|
10
10
|
strategy?: "afterInteractive" | "beforeInteractive" | "idle";
|
|
11
|
-
/** Unique identifier for this JSON-LD block */
|
|
12
11
|
id?: string;
|
|
13
12
|
}
|
|
14
13
|
export declare const useJsonLd: (data: JsonLdTypes | JsonLdTypes[], options?: UseJsonLdOptions) => {
|
|
15
|
-
injectJsonLd: (
|
|
14
|
+
injectJsonLd: (payload: JsonLdTypes | JsonLdTypes[]) => void;
|
|
16
15
|
removeJsonLd: () => void;
|
|
17
16
|
};
|
|
18
|
-
export
|
|
17
|
+
export {};
|
|
@@ -1,58 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useJsonLd
|
|
2
|
+
* `useJsonLd(data, options?)` hook.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Programmatic JSON-LD injection. Returns `inject`/`remove` callbacks
|
|
5
|
+
* so the caller can re-fire the injection on demand (e.g. after a route
|
|
6
|
+
* transition) or clean up manually.
|
|
6
7
|
*/
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const hashCache = new WeakMap();
|
|
11
|
-
const generateDataId = (data) => {
|
|
12
|
-
// Check cache first for better performance
|
|
13
|
-
if (hashCache.has(data)) {
|
|
14
|
-
return hashCache.get(data);
|
|
15
|
-
}
|
|
16
|
-
// Use base64 encoding for faster, more reliable hashing
|
|
17
|
-
const str = JSON.stringify(data);
|
|
18
|
-
// Optimized hashing using cyrb53 algorithm (better distribution & performance)
|
|
19
|
-
let h1 = 0xdeadbeef, h2 = 0x41c6ce57;
|
|
20
|
-
for (let i = 0, ch; i < str.length; i++) {
|
|
21
|
-
ch = str.charCodeAt(i);
|
|
22
|
-
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
23
|
-
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
24
|
-
}
|
|
25
|
-
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
26
|
-
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
27
|
-
const hash = (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36);
|
|
28
|
-
const result = `jsonld-${hash}`;
|
|
29
|
-
// Cache the result for future use
|
|
30
|
-
hashCache.set(data, result);
|
|
31
|
-
return result;
|
|
32
|
-
};
|
|
8
|
+
import { useCallback, useEffect, useMemo } from "react";
|
|
9
|
+
import { generateDataId } from "../core/hash.js";
|
|
10
|
+
const SCRIPT_TYPE = "application/ld+json";
|
|
33
11
|
export const useJsonLd = (data, options) => {
|
|
34
|
-
const { strategy = "afterInteractive", id } = options
|
|
35
|
-
// Generate stable IDs for data items
|
|
12
|
+
const { strategy = "afterInteractive", id } = options ?? {};
|
|
36
13
|
const dataIds = useMemo(() => {
|
|
37
|
-
const
|
|
38
|
-
return
|
|
14
|
+
const items = Array.isArray(data) ? data : [data];
|
|
15
|
+
return items.map((item, index) => id ? `${id}-${index}` : generateDataId(item));
|
|
39
16
|
}, [data, id]);
|
|
40
|
-
const injectJsonLd = useCallback((
|
|
17
|
+
const injectJsonLd = useCallback((payload) => {
|
|
41
18
|
if (typeof document === "undefined")
|
|
42
19
|
return;
|
|
43
|
-
const
|
|
44
|
-
const ids = Array.isArray(
|
|
45
|
-
?
|
|
20
|
+
const items = Array.isArray(payload) ? payload : [payload];
|
|
21
|
+
const ids = Array.isArray(payload) && !id
|
|
22
|
+
? items.map(generateDataId)
|
|
46
23
|
: dataIds;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
existingScript.remove();
|
|
52
|
-
}
|
|
53
|
-
// Create and inject new script
|
|
24
|
+
items.forEach((item, index) => {
|
|
25
|
+
document
|
|
26
|
+
.querySelector(`script[type="${SCRIPT_TYPE}"][data-seo-id="${ids[index]}"]`)
|
|
27
|
+
?.remove();
|
|
54
28
|
const script = document.createElement("script");
|
|
55
|
-
script.type =
|
|
29
|
+
script.type = SCRIPT_TYPE;
|
|
56
30
|
script.textContent = JSON.stringify(item);
|
|
57
31
|
script.setAttribute("data-seo-id", ids[index]);
|
|
58
32
|
script.setAttribute("data-seo-strategy", strategy);
|
|
@@ -62,24 +36,16 @@ export const useJsonLd = (data, options) => {
|
|
|
62
36
|
const removeJsonLd = useCallback(() => {
|
|
63
37
|
if (typeof document === "undefined")
|
|
64
38
|
return;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
39
|
+
for (const dataId of dataIds) {
|
|
40
|
+
document
|
|
41
|
+
.querySelector(`script[type="${SCRIPT_TYPE}"][data-seo-id="${dataId}"]`)
|
|
42
|
+
?.remove();
|
|
43
|
+
}
|
|
71
44
|
}, [dataIds]);
|
|
72
45
|
useEffect(() => {
|
|
73
|
-
if (data)
|
|
46
|
+
if (data)
|
|
74
47
|
injectJsonLd(data);
|
|
75
|
-
|
|
76
|
-
return () => {
|
|
77
|
-
removeJsonLd();
|
|
78
|
-
};
|
|
48
|
+
return () => removeJsonLd();
|
|
79
49
|
}, [data, injectJsonLd, removeJsonLd]);
|
|
80
|
-
return {
|
|
81
|
-
injectJsonLd,
|
|
82
|
-
removeJsonLd,
|
|
83
|
-
};
|
|
50
|
+
return { injectJsonLd, removeJsonLd };
|
|
84
51
|
};
|
|
85
|
-
export default useJsonLd;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useSEO(options)` hook.
|
|
3
|
+
*
|
|
4
|
+
* Imperative alternative to the `<SEO>` component for callers that need
|
|
5
|
+
* to derive SEO options from arbitrary React state without a wrapper.
|
|
6
|
+
*/
|
|
1
7
|
import type { SEOptions } from "../types/index.js";
|
|
2
8
|
export declare const useSEO: (options: SEOptions) => void;
|
|
@@ -1,37 +1,15 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
|
-
import { updateSEO } from "../utils/dom.js";
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* `useSEO(options)` hook.
|
|
3
|
+
*
|
|
4
|
+
* Imperative alternative to the `<SEO>` component for callers that need
|
|
5
|
+
* to derive SEO options from arbitrary React state without a wrapper.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return true;
|
|
11
|
-
// Handle null/undefined
|
|
12
|
-
if (a == null || b == null)
|
|
13
|
-
return a === b;
|
|
14
|
-
// Handle arrays
|
|
15
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
16
|
-
if (a.length !== b.length)
|
|
17
|
-
return false;
|
|
18
|
-
return a.every((item, index) => deepEqual(item, b[index]));
|
|
19
|
-
}
|
|
20
|
-
// Handle objects
|
|
21
|
-
if (typeof a === 'object' && typeof b === 'object' && a !== null && b !== null) {
|
|
22
|
-
const keysA = Object.keys(a);
|
|
23
|
-
const keysB = Object.keys(b);
|
|
24
|
-
if (keysA.length !== keysB.length)
|
|
25
|
-
return false;
|
|
26
|
-
return keysA.every(key => keysB.includes(key) && deepEqual(a[key], b[key]));
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
};
|
|
7
|
+
import { useEffect, useRef } from "react";
|
|
8
|
+
import { deepEqual } from "../core/deep-equal.js";
|
|
9
|
+
import { updateSEO } from "../utils/dom/index.js";
|
|
30
10
|
export const useSEO = (options) => {
|
|
31
|
-
// Use ref to store the previous options for deep comparison
|
|
32
11
|
const prevOptionsRef = useRef(null);
|
|
33
12
|
useEffect(() => {
|
|
34
|
-
// Only update if options have actually changed
|
|
35
13
|
if (!prevOptionsRef.current || !deepEqual(prevOptionsRef.current, options)) {
|
|
36
14
|
prevOptionsRef.current = options;
|
|
37
15
|
updateSEO(options);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helmet-compatible output for libraries that expect a `react-helmet`-style
|
|
3
|
+
* data shape (e.g. older Next.js APIs).
|
|
4
|
+
*
|
|
5
|
+
* This module is intentionally minimal: it only reports the title and html
|
|
6
|
+
* attributes. The full meta/link/JSON-LD output is available via `renderSEO`.
|
|
7
|
+
*/
|
|
8
|
+
import type { SEOptions } from "../types/index.js";
|
|
9
|
+
export interface RenderedMetaTag {
|
|
10
|
+
toString(): string;
|
|
11
|
+
toComponent(): unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface HelmetData {
|
|
14
|
+
base: RenderedMetaTag[];
|
|
15
|
+
bodyAttributes: Record<string, string>;
|
|
16
|
+
htmlAttributes: Record<string, string>;
|
|
17
|
+
link: RenderedMetaTag[];
|
|
18
|
+
meta: RenderedMetaTag[];
|
|
19
|
+
noscript: RenderedMetaTag[];
|
|
20
|
+
script: RenderedMetaTag[];
|
|
21
|
+
style: RenderedMetaTag[];
|
|
22
|
+
title: string;
|
|
23
|
+
titleAttributes: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
export declare const renderAsHelmet: (options: SEOptions) => HelmetData;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helmet-compatible output for libraries that expect a `react-helmet`-style
|
|
3
|
+
* data shape (e.g. older Next.js APIs).
|
|
4
|
+
*
|
|
5
|
+
* This module is intentionally minimal: it only reports the title and html
|
|
6
|
+
* attributes. The full meta/link/JSON-LD output is available via `renderSEO`.
|
|
7
|
+
*/
|
|
8
|
+
import { renderSEO } from "./renderer.js";
|
|
9
|
+
export const renderAsHelmet = (options) => {
|
|
10
|
+
const rendered = renderSEO(options);
|
|
11
|
+
return {
|
|
12
|
+
base: [],
|
|
13
|
+
bodyAttributes: {},
|
|
14
|
+
htmlAttributes: options.lang ? { lang: options.lang } : {},
|
|
15
|
+
link: [],
|
|
16
|
+
meta: [],
|
|
17
|
+
noscript: [],
|
|
18
|
+
script: [],
|
|
19
|
+
style: [],
|
|
20
|
+
title: rendered.title,
|
|
21
|
+
titleAttributes: {},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSR entry point.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the renderer, helmet adapter, and serializer.
|
|
5
|
+
*/
|
|
6
|
+
export { renderSEO, generateHead, extractSEOData, hydrateSEO } from "./renderer.js";
|
|
7
|
+
export { renderAsHelmet } from "./helmet.js";
|
|
8
|
+
export type { HelmetData, RenderedMetaTag } from "./helmet.js";
|
|
9
|
+
export type { RenderedSEO } from "./renderer.js";
|
|
10
|
+
export { serializeSEO, deserializeSEO, serializeSEOToBase64, deserializeSEOFromBase64, safeDeserializeSEO, } from "./serializer.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSR entry point.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the renderer, helmet adapter, and serializer.
|
|
5
|
+
*/
|
|
6
|
+
export { renderSEO, generateHead, extractSEOData, hydrateSEO } from "./renderer.js";
|
|
7
|
+
export { renderAsHelmet } from "./helmet.js";
|
|
8
|
+
export { serializeSEO, deserializeSEO, serializeSEOToBase64, deserializeSEOFromBase64, safeDeserializeSEO, } from "./serializer.js";
|
|
@@ -1,59 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SEO SSR Renderer
|
|
2
|
+
* SEO SSR Renderer.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Generates HTML strings for meta tags and structured data. Uses the same
|
|
5
|
+
* strategy registry as the DOM mutator, so DOM and SSR output are
|
|
6
|
+
* guaranteed to stay in sync.
|
|
6
7
|
*/
|
|
7
8
|
import type { SEOptions } from "../types/index.js";
|
|
8
9
|
export interface RenderedSEO {
|
|
9
|
-
/** Title tag */
|
|
10
10
|
title: string;
|
|
11
|
-
/** All meta tags as HTML */
|
|
12
11
|
meta: string;
|
|
13
|
-
/** All link tags as HTML */
|
|
14
12
|
link: string;
|
|
15
|
-
/** All JSON-LD scripts as HTML */
|
|
16
13
|
jsonLd: string;
|
|
17
|
-
/** Complete HTML head content */
|
|
18
14
|
toHTML(): string;
|
|
19
|
-
/** Convert to string (same as toHTML) */
|
|
20
15
|
toString(): string;
|
|
21
16
|
}
|
|
22
17
|
/**
|
|
23
|
-
* Render SEO options to HTML strings for server-side rendering
|
|
24
|
-
* Optimized with caching and efficient string building
|
|
18
|
+
* Render SEO options to HTML strings for server-side rendering.
|
|
25
19
|
*/
|
|
26
|
-
export declare const renderSEO: (options: SEOptions
|
|
20
|
+
export declare const renderSEO: (options: SEOptions) => RenderedSEO;
|
|
27
21
|
/**
|
|
28
|
-
* Generate complete
|
|
22
|
+
* Generate a complete `<head>` block for the given SEO options.
|
|
29
23
|
*/
|
|
30
24
|
export declare const generateHead: (options: SEOptions) => string;
|
|
31
25
|
/**
|
|
32
|
-
* Extract SEO
|
|
26
|
+
* Extract SEO options as a JSON string for client-side hydration.
|
|
33
27
|
*/
|
|
34
28
|
export declare const extractSEOData: (options: SEOptions) => string;
|
|
35
29
|
/**
|
|
36
|
-
* Hydrate SEO on client
|
|
37
|
-
*
|
|
30
|
+
* Hydrate SEO on the client by applying the deserialized options to the DOM.
|
|
31
|
+
* Swallows JSON parse errors and dynamic-import errors with a console error
|
|
32
|
+
* — the page should still render even if hydration fails.
|
|
38
33
|
*/
|
|
39
34
|
export declare const hydrateSEO: (serializedData: string) => void;
|
|
40
|
-
export interface RenderedMetaTag {
|
|
41
|
-
toString(): string;
|
|
42
|
-
toComponent(): unknown;
|
|
43
|
-
}
|
|
44
|
-
export interface HelmetData {
|
|
45
|
-
base: RenderedMetaTag[];
|
|
46
|
-
bodyAttributes: Record<string, string>;
|
|
47
|
-
htmlAttributes: Record<string, string>;
|
|
48
|
-
link: RenderedMetaTag[];
|
|
49
|
-
meta: RenderedMetaTag[];
|
|
50
|
-
noscript: RenderedMetaTag[];
|
|
51
|
-
script: RenderedMetaTag[];
|
|
52
|
-
style: RenderedMetaTag[];
|
|
53
|
-
title: string;
|
|
54
|
-
titleAttributes: Record<string, string>;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Render SEO in Helmet-compatible format
|
|
58
|
-
*/
|
|
59
|
-
export declare const renderAsHelmet: (options: SEOptions) => HelmetData;
|