@umituz/web-seo 2.1.0 → 2.2.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 +0 -9
- package/dist/domains/seo/components/JsonLd.js +0 -7
- package/dist/domains/seo/components/SEO.d.ts +0 -7
- package/dist/domains/seo/components/SEO.js +0 -7
- package/dist/domains/seo/components/index.d.ts +0 -5
- package/dist/domains/seo/components/index.js +0 -5
- package/dist/domains/seo/core/constants.d.ts +0 -6
- package/dist/domains/seo/core/constants.js +1 -7
- package/dist/domains/seo/core/deep-equal.d.ts +0 -7
- package/dist/domains/seo/core/deep-equal.js +0 -7
- package/dist/domains/seo/core/dom-queue.d.ts +0 -7
- package/dist/domains/seo/core/dom-queue.js +0 -10
- package/dist/domains/seo/core/escape.d.ts +0 -10
- package/dist/domains/seo/core/escape.js +0 -10
- package/dist/domains/seo/core/hash.d.ts +0 -8
- package/dist/domains/seo/core/hash.js +0 -8
- package/dist/domains/seo/core/init.d.ts +0 -11
- package/dist/domains/seo/core/init.js +0 -11
- package/dist/domains/seo/core/seo-strategies.d.ts +0 -10
- package/dist/domains/seo/core/seo-strategies.js +4 -75
- package/dist/domains/seo/core/seo-strategy.d.ts +1 -21
- package/dist/domains/seo/core/seo-strategy.js +0 -13
- package/dist/domains/seo/hooks/index.d.ts +0 -5
- package/dist/domains/seo/hooks/index.js +0 -5
- package/dist/domains/seo/hooks/useJsonLd.d.ts +0 -7
- package/dist/domains/seo/hooks/useJsonLd.js +0 -7
- package/dist/domains/seo/hooks/useSEO.d.ts +0 -6
- package/dist/domains/seo/hooks/useSEO.js +0 -6
- package/dist/domains/seo/ssr/helmet.d.ts +0 -7
- package/dist/domains/seo/ssr/helmet.js +0 -7
- package/dist/domains/seo/ssr/index.d.ts +0 -5
- package/dist/domains/seo/ssr/index.js +0 -5
- package/dist/domains/seo/ssr/renderer.d.ts +0 -21
- package/dist/domains/seo/ssr/renderer.js +0 -21
- package/dist/domains/seo/ssr/serializer.d.ts +0 -11
- package/dist/domains/seo/ssr/serializer.js +0 -11
- package/dist/domains/seo/types/schema.d.ts +0 -2
- package/dist/domains/seo/types/schema.js +0 -3
- package/dist/domains/seo/utils/dom/dom-context.d.ts +0 -11
- package/dist/domains/seo/utils/dom/dom-context.js +15 -15
- package/dist/domains/seo/utils/dom/dom-mutator.d.ts +0 -22
- package/dist/domains/seo/utils/dom/dom-mutator.js +1 -25
- package/dist/domains/seo/utils/index.d.ts +0 -5
- package/dist/domains/seo/utils/index.js +0 -8
- package/dist/domains/seo/utils/schema-generators/base.d.ts +0 -11
- package/dist/domains/seo/utils/schema-generators/base.js +0 -11
- package/dist/domains/seo/utils/schema-generators/factory.d.ts +0 -7
- package/dist/domains/seo/utils/schema-generators/factory.js +0 -7
- package/dist/domains/seo/utils/schema-generators/generators/article.js +1 -1
- package/dist/domains/seo/utils/schema-generators/index.d.ts +0 -6
- package/dist/domains/seo/utils/schema-generators/index.js +0 -6
- package/dist/domains/seo/utils/schema-generators/types.d.ts +0 -4
- package/dist/domains/seo/utils/schema-generators/types.js +0 -4
- package/dist/domains/seo/utils/validation/hreflang-validator.d.ts +0 -3
- package/dist/domains/seo/utils/validation/hreflang-validator.js +0 -3
- package/dist/domains/seo/utils/validation/image-validator.d.ts +0 -6
- package/dist/domains/seo/utils/validation/image-validator.js +0 -6
- package/dist/domains/seo/utils/validation/index.d.ts +0 -6
- package/dist/domains/seo/utils/validation/index.js +0 -6
- package/dist/domains/seo/utils/validation/jsonld-validator.d.ts +0 -7
- package/dist/domains/seo/utils/validation/jsonld-validator.js +0 -7
- package/dist/domains/seo/utils/validation/language-code.d.ts +0 -6
- package/dist/domains/seo/utils/validation/language-code.js +0 -6
- package/dist/domains/seo/utils/validation/length-validator.d.ts +0 -6
- package/dist/domains/seo/utils/validation/length-validator.js +0 -6
- package/dist/domains/seo/utils/validation/seo-auditor.d.ts +0 -14
- package/dist/domains/seo/utils/validation/seo-auditor.js +0 -24
- package/dist/domains/seo/utils/validation/text-helpers.d.ts +0 -6
- package/dist/domains/seo/utils/validation/text-helpers.js +0 -6
- package/dist/domains/seo/utils/validation/url-validator.d.ts +0 -6
- package/dist/domains/seo/utils/validation/url-validator.js +0 -6
- package/dist/domains/seo/vite/index.d.ts +1 -7
- package/dist/domains/seo/vite/index.js +0 -6
- package/dist/domains/seo/vite/plugin.d.ts +0 -6
- package/dist/domains/seo/vite/plugin.js +22 -14
- package/dist/domains/seo/vite/presets.d.ts +0 -6
- package/dist/domains/seo/vite/presets.js +0 -5
- package/dist/domains/seo/vite/robots-generator.d.ts +0 -3
- package/dist/domains/seo/vite/robots-generator.js +0 -3
- package/dist/domains/seo/vite/sitemap-generator.d.ts +0 -7
- package/dist/domains/seo/vite/sitemap-generator.js +0 -7
- package/dist/domains/seo/vite/types.d.ts +9 -11
- package/dist/domains/seo/vite/types.js +0 -3
- package/dist/index.js +0 -9
- package/package.json +1 -1
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `<JsonLd>` component.
|
|
3
|
-
*
|
|
4
|
-
* Injects one or more JSON-LD <script> tags into the document head.
|
|
5
|
-
* Each payload gets a stable id (cyrb53 hash) so re-renders with the
|
|
6
|
-
* same content re-use the existing node instead of appending a new one.
|
|
7
|
-
*/
|
|
8
1
|
import type { JsonLdTypes } from "../types/schema.js";
|
|
9
2
|
interface JsonLdProps {
|
|
10
3
|
data: JsonLdTypes | JsonLdTypes[];
|
|
11
|
-
/** Strategy label, attached as `data-seo-strategy` for debugging. */
|
|
12
4
|
strategy?: "afterInteractive" | "beforeInteractive" | "idle";
|
|
13
|
-
/** Optional explicit id; otherwise one is derived from the payload. */
|
|
14
5
|
id?: string;
|
|
15
6
|
}
|
|
16
7
|
export declare const JsonLd: import("react").MemoExoticComponent<({ data, strategy, id }: JsonLdProps) => null>;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `<JsonLd>` component.
|
|
3
|
-
*
|
|
4
|
-
* Injects one or more JSON-LD <script> tags into the document head.
|
|
5
|
-
* Each payload gets a stable id (cyrb53 hash) so re-renders with the
|
|
6
|
-
* same content re-use the existing node instead of appending a new one.
|
|
7
|
-
*/
|
|
8
1
|
import { memo, useEffect, useMemo, useRef } from "react";
|
|
9
2
|
import { deepEqual } from "../core/deep-equal.js";
|
|
10
3
|
import { generateDataId } from "../core/hash.js";
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `<SEO>` component.
|
|
3
|
-
*
|
|
4
|
-
* Applies SEO options to the document head on mount and whenever the
|
|
5
|
-
* props change. The deep-compare gate prevents re-running the DOM
|
|
6
|
-
* mutator when a parent re-renders with a structurally-equal object.
|
|
7
|
-
*/
|
|
8
1
|
import type { SEOptions } from "../types/index.js";
|
|
9
2
|
export declare const SEO: import("react").MemoExoticComponent<(props: SEOptions) => null>;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `<SEO>` component.
|
|
3
|
-
*
|
|
4
|
-
* Applies SEO options to the document head on mount and whenever the
|
|
5
|
-
* props change. The deep-compare gate prevents re-running the DOM
|
|
6
|
-
* mutator when a parent re-renders with a structurally-equal object.
|
|
7
|
-
*/
|
|
8
1
|
import { memo, useEffect, useRef } from "react";
|
|
9
2
|
import { deepEqual } from "../core/deep-equal.js";
|
|
10
3
|
import { updateSEO } from "../utils/dom/index.js";
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO Constants
|
|
3
|
-
*
|
|
4
|
-
* Centralized length and size thresholds for SEO validation.
|
|
5
|
-
* Used by both the validator and the generator modules.
|
|
6
|
-
*/
|
|
7
1
|
export declare const TITLE_MIN_LENGTH = 30;
|
|
8
2
|
export declare const TITLE_MAX_LENGTH = 60;
|
|
9
3
|
export declare const DESCRIPTION_MIN_LENGTH = 120;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO Constants
|
|
3
|
-
*
|
|
4
|
-
* Centralized length and size thresholds for SEO validation.
|
|
5
|
-
* Used by both the validator and the generator modules.
|
|
6
|
-
*/
|
|
7
1
|
export const TITLE_MIN_LENGTH = 30;
|
|
8
2
|
export const TITLE_MAX_LENGTH = 60;
|
|
9
3
|
export const DESCRIPTION_MIN_LENGTH = 120;
|
|
10
4
|
export const DESCRIPTION_MAX_LENGTH = 160;
|
|
11
5
|
export const OG_IMAGE_MIN_WIDTH = 1200;
|
|
12
6
|
export const OG_IMAGE_MIN_HEIGHT = 630;
|
|
13
|
-
export const OG_IMAGE_MAX_SIZE = 8 * 1024 * 1024;
|
|
7
|
+
export const OG_IMAGE_MAX_SIZE = 8 * 1024 * 1024;
|
|
14
8
|
export const SCHEMA_CONTEXT = "https://schema.org";
|
|
15
9
|
export const DEFAULT_CACHE_LIMIT = 1000;
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deep equality for SEO options and JSON-LD payloads.
|
|
3
|
-
*
|
|
4
|
-
* Used by React component memoization, the useSEO hook, and the JsonLd hook
|
|
5
|
-
* to avoid re-running DOM mutations or re-injecting <script> tags when the
|
|
6
|
-
* incoming object reference changes but the content is structurally equal.
|
|
7
|
-
*/
|
|
8
1
|
export declare const deepEqual: (a: unknown, b: unknown) => boolean;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deep equality for SEO options and JSON-LD payloads.
|
|
3
|
-
*
|
|
4
|
-
* Used by React component memoization, the useSEO hook, and the JsonLd hook
|
|
5
|
-
* to avoid re-running DOM mutations or re-injecting <script> tags when the
|
|
6
|
-
* incoming object reference changes but the content is structurally equal.
|
|
7
|
-
*/
|
|
8
1
|
export const deepEqual = (a, b) => {
|
|
9
2
|
if (a === b)
|
|
10
3
|
return true;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Batched DOM update queue.
|
|
3
|
-
*
|
|
4
|
-
* Coalesces many small SEO mutations into a single requestAnimationFrame
|
|
5
|
-
* pass, preventing layout thrashing and giving us a single try/catch
|
|
6
|
-
* boundary for all queued work.
|
|
7
|
-
*/
|
|
8
1
|
type DOMUpdate = () => void;
|
|
9
2
|
export declare const queueDOMUpdate: (update: DOMUpdate) => void;
|
|
10
3
|
export {};
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Batched DOM update queue.
|
|
3
|
-
*
|
|
4
|
-
* Coalesces many small SEO mutations into a single requestAnimationFrame
|
|
5
|
-
* pass, preventing layout thrashing and giving us a single try/catch
|
|
6
|
-
* boundary for all queued work.
|
|
7
|
-
*/
|
|
8
1
|
const updateQueue = [];
|
|
9
2
|
let scheduled = false;
|
|
10
3
|
const flush = () => {
|
|
@@ -15,12 +8,9 @@ const flush = () => {
|
|
|
15
8
|
update();
|
|
16
9
|
}
|
|
17
10
|
catch (error) {
|
|
18
|
-
// Surface the error: silent failure here would leave the DOM
|
|
19
|
-
// silently half-updated and impossible to debug.
|
|
20
11
|
console.error("[SEO] DOM update failed:", error);
|
|
21
12
|
}
|
|
22
13
|
}
|
|
23
|
-
// Re-entries during this flush get rescheduled.
|
|
24
14
|
if (updateQueue.length > 0) {
|
|
25
15
|
schedule();
|
|
26
16
|
}
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTML / JSON escaping for safe SSR output.
|
|
3
|
-
*
|
|
4
|
-
* Bounded caches prevent unbounded growth when the renderer is fed many
|
|
5
|
-
* long-lived pages on a Node server.
|
|
6
|
-
*/
|
|
7
1
|
export declare const escapeHTML: (str: string) => string;
|
|
8
|
-
/**
|
|
9
|
-
* Escape JSON for inclusion inside a <script> tag.
|
|
10
|
-
* Prevents `</script>` inside user JSON from breaking out of the script.
|
|
11
|
-
*/
|
|
12
2
|
export declare const escapeJSONForScript: (json: string) => string;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTML / JSON escaping for safe SSR output.
|
|
3
|
-
*
|
|
4
|
-
* Bounded caches prevent unbounded growth when the renderer is fed many
|
|
5
|
-
* long-lived pages on a Node server.
|
|
6
|
-
*/
|
|
7
1
|
import { DEFAULT_CACHE_LIMIT } from "./constants.js";
|
|
8
2
|
const escapeCache = new Map();
|
|
9
3
|
const pushCached = (key, value) => {
|
|
@@ -29,10 +23,6 @@ export const escapeHTML = (str) => {
|
|
|
29
23
|
});
|
|
30
24
|
return pushCached(str, escaped);
|
|
31
25
|
};
|
|
32
|
-
/**
|
|
33
|
-
* Escape JSON for inclusion inside a <script> tag.
|
|
34
|
-
* Prevents `</script>` inside user JSON from breaking out of the script.
|
|
35
|
-
*/
|
|
36
26
|
export const escapeJSONForScript = (json) => {
|
|
37
27
|
const cacheKey = `json:${json}`;
|
|
38
28
|
if (escapeCache.has(cacheKey))
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cyrb53 content hash with WeakMap memoization.
|
|
3
|
-
*
|
|
4
|
-
* Produces a stable, URL-safe id from any JSON-LD payload. Used by both
|
|
5
|
-
* the JsonLd component and the useJsonLd hook to give each schema instance
|
|
6
|
-
* a deterministic script-tag id, so the same payload re-uses the same <script>
|
|
7
|
-
* node and the DOM stays clean.
|
|
8
|
-
*/
|
|
9
1
|
export declare const generateDataId: (data: object) => string;
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cyrb53 content hash with WeakMap memoization.
|
|
3
|
-
*
|
|
4
|
-
* Produces a stable, URL-safe id from any JSON-LD payload. Used by both
|
|
5
|
-
* the JsonLd component and the useJsonLd hook to give each schema instance
|
|
6
|
-
* a deterministic script-tag id, so the same payload re-uses the same <script>
|
|
7
|
-
* node and the DOM stays clean.
|
|
8
|
-
*/
|
|
9
1
|
const hashCache = new WeakMap();
|
|
10
2
|
const cyrb53 = (str) => {
|
|
11
3
|
let h1 = 0xdeadbeef;
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `initSEO(config)` — application-level SEO bootstrap.
|
|
3
|
-
*
|
|
4
|
-
* Sets default SEO options on first call and re-applies them whenever
|
|
5
|
-
* the i18n instance reports a language change. Returns a cleanup
|
|
6
|
-
* function that detaches the listener.
|
|
7
|
-
*
|
|
8
|
-
* i18n is modeled as a Strategy via the `I18nInstance` interface; any
|
|
9
|
-
* adapter exposing `t`, `on`, and `language` works (i18next, react-intl,
|
|
10
|
-
* etc.) without a hard dependency.
|
|
11
|
-
*/
|
|
12
1
|
import type { SEOConfig } from "../types/index.js";
|
|
13
2
|
interface I18nInstance {
|
|
14
3
|
language?: string;
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `initSEO(config)` — application-level SEO bootstrap.
|
|
3
|
-
*
|
|
4
|
-
* Sets default SEO options on first call and re-applies them whenever
|
|
5
|
-
* the i18n instance reports a language change. Returns a cleanup
|
|
6
|
-
* function that detaches the listener.
|
|
7
|
-
*
|
|
8
|
-
* i18n is modeled as a Strategy via the `I18nInstance` interface; any
|
|
9
|
-
* adapter exposing `t`, `on`, and `language` works (i18next, react-intl,
|
|
10
|
-
* etc.) without a hard dependency.
|
|
11
|
-
*/
|
|
12
1
|
import { updateSEO } from "../utils/dom/index.js";
|
|
13
2
|
export const initSEO = (config) => {
|
|
14
3
|
if (typeof window === "undefined")
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO tag strategies (Strategy pattern).
|
|
3
|
-
*
|
|
4
|
-
* One strategy per concern. The same strategy is consumed by:
|
|
5
|
-
* - `dom/dom-mutator.ts` – applies the change to the live DOM
|
|
6
|
-
* - `ssr/renderer.ts` – serializes the change to an HTML string
|
|
7
|
-
*
|
|
8
|
-
* Replaces the historical god-functions in `dom.ts` and `renderer.ts` and
|
|
9
|
-
* fixes the divergence where SSR silently dropped OG image width/height.
|
|
10
|
-
*/
|
|
11
1
|
import type { Strategy } from "./seo-strategy.js";
|
|
12
2
|
export declare const titleStrategy: Strategy;
|
|
13
3
|
export declare const langStrategy: Strategy;
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO tag strategies (Strategy pattern).
|
|
3
|
-
*
|
|
4
|
-
* One strategy per concern. The same strategy is consumed by:
|
|
5
|
-
* - `dom/dom-mutator.ts` – applies the change to the live DOM
|
|
6
|
-
* - `ssr/renderer.ts` – serializes the change to an HTML string
|
|
7
|
-
*
|
|
8
|
-
* Replaces the historical god-functions in `dom.ts` and `renderer.ts` and
|
|
9
|
-
* fixes the divergence where SSR silently dropped OG image width/height.
|
|
10
|
-
*/
|
|
11
1
|
import { escapeHTML, escapeJSONForScript } from "./escape.js";
|
|
12
2
|
const ATTR = {
|
|
13
3
|
rel: "rel",
|
|
@@ -48,7 +38,6 @@ const robotsDirectivesToMeta = (directives) => {
|
|
|
48
38
|
case "noimageindex":
|
|
49
39
|
meta.imageIndex = false;
|
|
50
40
|
break;
|
|
51
|
-
// "unavailable_after" needs a date and is exposed via RobotsMeta only.
|
|
52
41
|
}
|
|
53
42
|
}
|
|
54
43
|
return meta;
|
|
@@ -79,9 +68,6 @@ const robotsMetaToString = (robots) => {
|
|
|
79
68
|
directives.push(`unavailable_after:${robots.unavailableAfter}`);
|
|
80
69
|
return directives.join(", ");
|
|
81
70
|
};
|
|
82
|
-
// ============================================================================
|
|
83
|
-
// Title
|
|
84
|
-
// ============================================================================
|
|
85
71
|
export const titleStrategy = {
|
|
86
72
|
id: "title",
|
|
87
73
|
applies: (o) => Boolean(o.title || o.titleTemplate),
|
|
@@ -95,9 +81,6 @@ export const titleStrategy = {
|
|
|
95
81
|
ctx.meta.unshift(`<title>${escapeHTML(value ?? "")}</title>`);
|
|
96
82
|
},
|
|
97
83
|
};
|
|
98
|
-
// ============================================================================
|
|
99
|
-
// Language
|
|
100
|
-
// ============================================================================
|
|
101
84
|
export const langStrategy = {
|
|
102
85
|
id: "lang",
|
|
103
86
|
applies: (o) => Boolean(o.lang),
|
|
@@ -106,15 +89,10 @@ export const langStrategy = {
|
|
|
106
89
|
document.documentElement.lang = o.lang;
|
|
107
90
|
},
|
|
108
91
|
applyHTML: (o, ctx) => {
|
|
109
|
-
// <html lang> is emitted by the renderer wrapper, but we expose lang
|
|
110
|
-
// through a special sentinel line that the head wrapper reads.
|
|
111
92
|
if (o.lang)
|
|
112
93
|
ctx.meta.push(`<!-- lang:${o.lang} -->`);
|
|
113
94
|
},
|
|
114
95
|
};
|
|
115
|
-
// ============================================================================
|
|
116
|
-
// Description
|
|
117
|
-
// ============================================================================
|
|
118
96
|
export const descriptionStrategy = {
|
|
119
97
|
id: "description",
|
|
120
98
|
applies: (o) => Boolean(o.description),
|
|
@@ -127,9 +105,6 @@ export const descriptionStrategy = {
|
|
|
127
105
|
ctx.meta.push(`<meta name="description" content="${escapeHTML(o.description)}" />`);
|
|
128
106
|
},
|
|
129
107
|
};
|
|
130
|
-
// ============================================================================
|
|
131
|
-
// Canonical
|
|
132
|
-
// ============================================================================
|
|
133
108
|
export const canonicalStrategy = {
|
|
134
109
|
id: "canonical",
|
|
135
110
|
applies: (o) => Boolean(o.canonical),
|
|
@@ -142,9 +117,6 @@ export const canonicalStrategy = {
|
|
|
142
117
|
ctx.link.push(`<link rel="canonical" href="${escapeHTML(o.canonical)}" />`);
|
|
143
118
|
},
|
|
144
119
|
};
|
|
145
|
-
// ============================================================================
|
|
146
|
-
// Robots
|
|
147
|
-
// ============================================================================
|
|
148
120
|
export const robotsStrategy = {
|
|
149
121
|
id: "robots",
|
|
150
122
|
applies: (o) => o.robots !== undefined,
|
|
@@ -161,9 +133,6 @@ export const robotsStrategy = {
|
|
|
161
133
|
ctx.meta.push(`<meta name="robots" content="${escapeHTML(robotsMetaToString(meta))}" />`);
|
|
162
134
|
},
|
|
163
135
|
};
|
|
164
|
-
// ============================================================================
|
|
165
|
-
// Viewport
|
|
166
|
-
// ============================================================================
|
|
167
136
|
export const viewportStrategy = {
|
|
168
137
|
id: "viewport",
|
|
169
138
|
applies: (o) => Boolean(o.viewport),
|
|
@@ -176,9 +145,6 @@ export const viewportStrategy = {
|
|
|
176
145
|
ctx.meta.push(`<meta name="viewport" content="${escapeHTML(o.viewport)}" />`);
|
|
177
146
|
},
|
|
178
147
|
};
|
|
179
|
-
// ============================================================================
|
|
180
|
-
// Theme color
|
|
181
|
-
// ============================================================================
|
|
182
148
|
export const themeColorStrategy = {
|
|
183
149
|
id: "theme-color",
|
|
184
150
|
applies: (o) => Boolean(o.themeColor),
|
|
@@ -191,9 +157,6 @@ export const themeColorStrategy = {
|
|
|
191
157
|
ctx.meta.push(`<meta name="theme-color" content="${escapeHTML(o.themeColor)}" />`);
|
|
192
158
|
},
|
|
193
159
|
};
|
|
194
|
-
// ============================================================================
|
|
195
|
-
// Favicons
|
|
196
|
-
// ============================================================================
|
|
197
160
|
export const faviconStrategy = {
|
|
198
161
|
id: "favicons",
|
|
199
162
|
applies: (o) => Boolean(o.favicon || o.appleTouchIcon || o.maskIcon),
|
|
@@ -214,16 +177,12 @@ export const faviconStrategy = {
|
|
|
214
177
|
ctx.link.push(`<link rel="mask-icon" href="${escapeHTML(o.maskIcon)}" />`);
|
|
215
178
|
},
|
|
216
179
|
};
|
|
217
|
-
// ============================================================================
|
|
218
|
-
// Hreflang
|
|
219
|
-
// ============================================================================
|
|
220
180
|
export const hreflangStrategy = {
|
|
221
181
|
id: "hreflang",
|
|
222
182
|
applies: (o) => Boolean(o.hreflang && o.hreflang.length > 0),
|
|
223
183
|
applyDOM: (o, ctx) => {
|
|
224
184
|
if (!o.hreflang)
|
|
225
185
|
return;
|
|
226
|
-
// Drop stale hreflang tags first.
|
|
227
186
|
document.querySelectorAll('link[rel="alternate"][hreflang]').forEach((el) => el.remove());
|
|
228
187
|
for (const entry of o.hreflang) {
|
|
229
188
|
ctx.setLink({ [ATTR.rel]: "alternate", [ATTR.hreflang]: entry.lang, [ATTR.href]: entry.url });
|
|
@@ -237,9 +196,6 @@ export const hreflangStrategy = {
|
|
|
237
196
|
}
|
|
238
197
|
},
|
|
239
198
|
};
|
|
240
|
-
// ============================================================================
|
|
241
|
-
// Preload / Preconnect / DNS prefetch
|
|
242
|
-
// ============================================================================
|
|
243
199
|
const buildPreloadAttrs = (preload) => {
|
|
244
200
|
const attrs = { [ATTR.rel]: "preload", [ATTR.href]: preload.href, [ATTR.as]: preload.as };
|
|
245
201
|
if (preload.type)
|
|
@@ -312,9 +268,6 @@ export const dnsPrefetchStrategy = {
|
|
|
312
268
|
}
|
|
313
269
|
},
|
|
314
270
|
};
|
|
315
|
-
// ============================================================================
|
|
316
|
-
// Custom meta tags
|
|
317
|
-
// ============================================================================
|
|
318
271
|
export const customMetaStrategy = {
|
|
319
272
|
id: "custom-meta",
|
|
320
273
|
applies: (o) => Boolean(o.meta && o.meta.length > 0),
|
|
@@ -343,9 +296,6 @@ export const customMetaStrategy = {
|
|
|
343
296
|
}
|
|
344
297
|
},
|
|
345
298
|
};
|
|
346
|
-
// ============================================================================
|
|
347
|
-
// Custom link tags
|
|
348
|
-
// ============================================================================
|
|
349
299
|
export const customLinkStrategy = {
|
|
350
300
|
id: "custom-link",
|
|
351
301
|
applies: (o) => Boolean(o.link && o.link.length > 0),
|
|
@@ -386,9 +336,6 @@ export const customLinkStrategy = {
|
|
|
386
336
|
}
|
|
387
337
|
},
|
|
388
338
|
};
|
|
389
|
-
// ============================================================================
|
|
390
|
-
// Open Graph
|
|
391
|
-
// ============================================================================
|
|
392
339
|
const ogProperty = (name, value, ctx) => {
|
|
393
340
|
if (!value)
|
|
394
341
|
return;
|
|
@@ -399,8 +346,6 @@ const ogImageTags = (image) => {
|
|
|
399
346
|
if (!image)
|
|
400
347
|
return sink;
|
|
401
348
|
if (Array.isArray(image)) {
|
|
402
|
-
// Spec: emit one <meta property="og:image" ...> per image, plus
|
|
403
|
-
// per-image og:image:width / :height / :alt / :type.
|
|
404
349
|
for (const img of image) {
|
|
405
350
|
ogProperty("image", img.url, sink);
|
|
406
351
|
if (img.width)
|
|
@@ -544,15 +489,6 @@ export const openGraphStrategy = {
|
|
|
544
489
|
}
|
|
545
490
|
},
|
|
546
491
|
};
|
|
547
|
-
// ============================================================================
|
|
548
|
-
// Twitter Card
|
|
549
|
-
// ============================================================================
|
|
550
|
-
/**
|
|
551
|
-
* Twitter cards should fall back to OpenGraph values for the common
|
|
552
|
-
* title/description/image fields when those are omitted. We only pick
|
|
553
|
-
* the overlapping fields — Twitter has no concept of OG's `firstName`,
|
|
554
|
-
* `product`, etc.
|
|
555
|
-
*/
|
|
556
492
|
const twitterFallback = (twitter, openGraph) => ({
|
|
557
493
|
cardType: twitter.cardType,
|
|
558
494
|
site: twitter.site,
|
|
@@ -651,17 +587,13 @@ export const twitterStrategy = {
|
|
|
651
587
|
}
|
|
652
588
|
},
|
|
653
589
|
};
|
|
654
|
-
// ============================================================================
|
|
655
|
-
// JSON-LD
|
|
656
|
-
// ============================================================================
|
|
657
590
|
export const jsonLdStrategy = {
|
|
658
591
|
id: "json-ld",
|
|
659
592
|
applies: (o) => Boolean(o.jsonLd && o.jsonLd.length > 0),
|
|
660
|
-
applyDOM: () => {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
// duplicate all of that logic, so we no-op here intentionally.
|
|
593
|
+
applyDOM: (o, ctx) => {
|
|
594
|
+
if (!o.jsonLd)
|
|
595
|
+
return;
|
|
596
|
+
ctx.setJsonLd(o.jsonLd);
|
|
665
597
|
},
|
|
666
598
|
applyHTML: (o, ctx) => {
|
|
667
599
|
if (!o.jsonLd)
|
|
@@ -671,9 +603,6 @@ export const jsonLdStrategy = {
|
|
|
671
603
|
}
|
|
672
604
|
},
|
|
673
605
|
};
|
|
674
|
-
// ============================================================================
|
|
675
|
-
// Registry
|
|
676
|
-
// ============================================================================
|
|
677
606
|
export const SEO_STRATEGIES = Object.freeze([
|
|
678
607
|
titleStrategy,
|
|
679
608
|
descriptionStrategy,
|
|
@@ -1,37 +1,17 @@
|
|
|
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
1
|
import type { SEOptions } from "../types/index.js";
|
|
15
|
-
/** Output for the DOM: a side-effect applied to `document.head`. */
|
|
16
2
|
export interface DOMContext {
|
|
17
|
-
/** Apply or update a `<meta>` tag. `undefined` content is a no-op. */
|
|
18
3
|
setMeta: (name: string, content: string | undefined) => void;
|
|
19
|
-
/** Apply or update a `<link>` tag. */
|
|
20
4
|
setLink: (attrs: Record<string, string>) => void;
|
|
5
|
+
setJsonLd: (data: unknown[]) => void;
|
|
21
6
|
}
|
|
22
|
-
/** Output for SSR: a builder that collects tags as HTML strings. */
|
|
23
7
|
export interface HTMLContext {
|
|
24
8
|
meta: string[];
|
|
25
9
|
link: string[];
|
|
26
10
|
jsonLd: string[];
|
|
27
11
|
}
|
|
28
12
|
export interface Strategy {
|
|
29
|
-
/** Stable key, useful for debugging and tests. */
|
|
30
13
|
readonly id: string;
|
|
31
|
-
/** Returns true when the strategy has work to do for these options. */
|
|
32
14
|
applies(options: SEOptions): boolean;
|
|
33
|
-
/** Apply to the live DOM. */
|
|
34
15
|
applyDOM(options: SEOptions, ctx: DOMContext): void;
|
|
35
|
-
/** Append HTML strings to the SSR context. */
|
|
36
16
|
applyHTML(options: SEOptions, ctx: HTMLContext): void;
|
|
37
17
|
}
|
|
@@ -1,14 +1 @@
|
|
|
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
1
|
export {};
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `useJsonLd(data, options?)` hook.
|
|
3
|
-
*
|
|
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.
|
|
7
|
-
*/
|
|
8
1
|
import type { JsonLdTypes } from "../types/schema.js";
|
|
9
2
|
interface UseJsonLdOptions {
|
|
10
3
|
strategy?: "afterInteractive" | "beforeInteractive" | "idle";
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `useJsonLd(data, options?)` hook.
|
|
3
|
-
*
|
|
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.
|
|
7
|
-
*/
|
|
8
1
|
import { useCallback, useEffect, useMemo } from "react";
|
|
9
2
|
import { generateDataId } from "../core/hash.js";
|
|
10
3
|
const SCRIPT_TYPE = "application/ld+json";
|
|
@@ -1,8 +1,2 @@
|
|
|
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
|
-
*/
|
|
7
1
|
import type { SEOptions } from "../types/index.js";
|
|
8
2
|
export declare const useSEO: (options: SEOptions) => void;
|
|
@@ -1,9 +1,3 @@
|
|
|
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
|
-
*/
|
|
7
1
|
import { useEffect, useRef } from "react";
|
|
8
2
|
import { deepEqual } from "../core/deep-equal.js";
|
|
9
3
|
import { updateSEO } from "../utils/dom/index.js";
|
|
@@ -1,10 +1,3 @@
|
|
|
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
1
|
import type { SEOptions } from "../types/index.js";
|
|
9
2
|
export interface RenderedMetaTag {
|
|
10
3
|
toString(): string;
|
|
@@ -1,10 +1,3 @@
|
|
|
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
1
|
import { renderSEO } from "./renderer.js";
|
|
9
2
|
export const renderAsHelmet = (options) => {
|
|
10
3
|
const rendered = renderSEO(options);
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SSR entry point.
|
|
3
|
-
*
|
|
4
|
-
* Re-exports the renderer, helmet adapter, and serializer.
|
|
5
|
-
*/
|
|
6
1
|
export { renderSEO, generateHead, extractSEOData, hydrateSEO } from "./renderer.js";
|
|
7
2
|
export { renderAsHelmet } from "./helmet.js";
|
|
8
3
|
export type { HelmetData, RenderedMetaTag } from "./helmet.js";
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SSR entry point.
|
|
3
|
-
*
|
|
4
|
-
* Re-exports the renderer, helmet adapter, and serializer.
|
|
5
|
-
*/
|
|
6
1
|
export { renderSEO, generateHead, extractSEOData, hydrateSEO } from "./renderer.js";
|
|
7
2
|
export { renderAsHelmet } from "./helmet.js";
|
|
8
3
|
export { serializeSEO, deserializeSEO, serializeSEOToBase64, deserializeSEOFromBase64, safeDeserializeSEO, } from "./serializer.js";
|