@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,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO SSR Renderer.
|
|
3
|
-
*
|
|
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.
|
|
7
|
-
*/
|
|
8
1
|
import type { SEOptions } from "../types/index.js";
|
|
9
2
|
export interface RenderedSEO {
|
|
10
3
|
title: string;
|
|
@@ -14,21 +7,7 @@ export interface RenderedSEO {
|
|
|
14
7
|
toHTML(): string;
|
|
15
8
|
toString(): string;
|
|
16
9
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Render SEO options to HTML strings for server-side rendering.
|
|
19
|
-
*/
|
|
20
10
|
export declare const renderSEO: (options: SEOptions) => RenderedSEO;
|
|
21
|
-
/**
|
|
22
|
-
* Generate a complete `<head>` block for the given SEO options.
|
|
23
|
-
*/
|
|
24
11
|
export declare const generateHead: (options: SEOptions) => string;
|
|
25
|
-
/**
|
|
26
|
-
* Extract SEO options as a JSON string for client-side hydration.
|
|
27
|
-
*/
|
|
28
12
|
export declare const extractSEOData: (options: SEOptions) => string;
|
|
29
|
-
/**
|
|
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.
|
|
33
|
-
*/
|
|
34
13
|
export declare const hydrateSEO: (serializedData: string) => void;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO SSR Renderer.
|
|
3
|
-
*
|
|
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.
|
|
7
|
-
*/
|
|
8
1
|
import { escapeHTML } from "../core/escape.js";
|
|
9
2
|
import { SEO_STRATEGIES } from "../core/seo-strategies.js";
|
|
10
3
|
import { updateSEO } from "../utils/dom/index.js";
|
|
@@ -20,9 +13,6 @@ const findTitle = (meta) => {
|
|
|
20
13
|
return match ? match[1] : "";
|
|
21
14
|
};
|
|
22
15
|
const stripTitle = (meta) => meta.replace(/<title>[\s\S]*?<\/title>\n?/, "");
|
|
23
|
-
/**
|
|
24
|
-
* Render SEO options to HTML strings for server-side rendering.
|
|
25
|
-
*/
|
|
26
16
|
export const renderSEO = (options) => {
|
|
27
17
|
const ctx = buildHTMLContext();
|
|
28
18
|
for (const strategy of SEO_STRATEGIES) {
|
|
@@ -53,9 +43,6 @@ export const renderSEO = (options) => {
|
|
|
53
43
|
},
|
|
54
44
|
};
|
|
55
45
|
};
|
|
56
|
-
/**
|
|
57
|
-
* Generate a complete `<head>` block for the given SEO options.
|
|
58
|
-
*/
|
|
59
46
|
export const generateHead = (options) => {
|
|
60
47
|
const rendered = renderSEO(options);
|
|
61
48
|
const langAttr = options.lang ? ` lang="${escapeHTML(options.lang)}"` : "";
|
|
@@ -66,15 +53,7 @@ export const generateHead = (options) => {
|
|
|
66
53
|
.join("\n");
|
|
67
54
|
return ` <head${langAttr}>\n${indented}\n </head>`;
|
|
68
55
|
};
|
|
69
|
-
/**
|
|
70
|
-
* Extract SEO options as a JSON string for client-side hydration.
|
|
71
|
-
*/
|
|
72
56
|
export const extractSEOData = (options) => JSON.stringify(options);
|
|
73
|
-
/**
|
|
74
|
-
* Hydrate SEO on the client by applying the deserialized options to the DOM.
|
|
75
|
-
* Swallows JSON parse errors and dynamic-import errors with a console error
|
|
76
|
-
* — the page should still render even if hydration fails.
|
|
77
|
-
*/
|
|
78
57
|
export const hydrateSEO = (serializedData) => {
|
|
79
58
|
if (typeof window === "undefined")
|
|
80
59
|
return;
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO Serializer
|
|
3
|
-
*
|
|
4
|
-
* JSON and base64 (de)serialization of SEO options for SSR/hydration.
|
|
5
|
-
* Uses TextEncoder/TextDecoder for UTF-8 safety in the browser, and
|
|
6
|
-
* Buffer in Node when available.
|
|
7
|
-
*/
|
|
8
1
|
import type { SEOptions } from "../types/index.js";
|
|
9
2
|
export declare const serializeSEO: (options: SEOptions) => string;
|
|
10
3
|
export declare const deserializeSEO: (data: string) => SEOptions;
|
|
11
4
|
export declare const serializeSEOToBase64: (options: SEOptions) => string;
|
|
12
5
|
export declare const deserializeSEOFromBase64: (base64: string) => SEOptions;
|
|
13
|
-
/**
|
|
14
|
-
* Safe deserialize: returns `null` instead of throwing on invalid input.
|
|
15
|
-
* Use this when consuming data from an untrusted source (URL params, cookies).
|
|
16
|
-
*/
|
|
17
6
|
export declare const safeDeserializeSEO: (data: string) => SEOptions | null;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO Serializer
|
|
3
|
-
*
|
|
4
|
-
* JSON and base64 (de)serialization of SEO options for SSR/hydration.
|
|
5
|
-
* Uses TextEncoder/TextDecoder for UTF-8 safety in the browser, and
|
|
6
|
-
* Buffer in Node when available.
|
|
7
|
-
*/
|
|
8
1
|
export const serializeSEO = (options) => JSON.stringify(options);
|
|
9
2
|
export const deserializeSEO = (data) => {
|
|
10
3
|
try {
|
|
@@ -34,10 +27,6 @@ const fromBase64 = (base64) => {
|
|
|
34
27
|
};
|
|
35
28
|
export const serializeSEOToBase64 = (options) => toBase64(serializeSEO(options));
|
|
36
29
|
export const deserializeSEOFromBase64 = (base64) => deserializeSEO(fromBase64(base64));
|
|
37
|
-
/**
|
|
38
|
-
* Safe deserialize: returns `null` instead of throwing on invalid input.
|
|
39
|
-
* Use this when consuming data from an untrusted source (URL params, cookies).
|
|
40
|
-
*/
|
|
41
30
|
export const safeDeserializeSEO = (data) => {
|
|
42
31
|
try {
|
|
43
32
|
const parsed = JSON.parse(data);
|
|
@@ -225,8 +225,6 @@ export interface CourseJsonLd extends Thing {
|
|
|
225
225
|
export type JsonLdTypes = ArticleJsonLd | ProductJsonLd | OrganizationJsonLd | LocalBusinessJsonLd | BreadcrumbJsonLd | FAQJsonLd | WebSiteJsonLd | PersonJsonLd | VideoJsonLd | AudioJsonLd | BookJsonLd | CourseJsonLd;
|
|
226
226
|
export type SchemaType = JsonLdTypes["@type"];
|
|
227
227
|
export interface SchemaGeneratorOptions {
|
|
228
|
-
/** Strict mode - throws errors instead of warnings */
|
|
229
228
|
strict?: boolean;
|
|
230
|
-
/** Validate generated schema against Schema.org requirements */
|
|
231
229
|
validate?: boolean;
|
|
232
230
|
}
|
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOMContext implementation.
|
|
3
|
-
*
|
|
4
|
-
* Implements the low-level `setMeta` / `setLink` operations that the SEO
|
|
5
|
-
* strategies call into. Each call is idempotent: it finds the existing
|
|
6
|
-
* <meta>/<link> node by attribute and updates it in place, or creates a
|
|
7
|
-
* new one tagged with `data-seo="true"` so `clearSEO` can remove it.
|
|
8
|
-
*
|
|
9
|
-
* Tagged with `data-seo` so `clearSEO` can later remove only the nodes
|
|
10
|
-
* this library owns, leaving user-added tags untouched.
|
|
11
|
-
*/
|
|
12
1
|
import type { DOMContext } from "../../core/seo-strategy.js";
|
|
13
2
|
export declare const createDOMContext: () => DOMContext;
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOMContext implementation.
|
|
3
|
-
*
|
|
4
|
-
* Implements the low-level `setMeta` / `setLink` operations that the SEO
|
|
5
|
-
* strategies call into. Each call is idempotent: it finds the existing
|
|
6
|
-
* <meta>/<link> node by attribute and updates it in place, or creates a
|
|
7
|
-
* new one tagged with `data-seo="true"` so `clearSEO` can remove it.
|
|
8
|
-
*
|
|
9
|
-
* Tagged with `data-seo` so `clearSEO` can later remove only the nodes
|
|
10
|
-
* this library owns, leaving user-added tags untouched.
|
|
11
|
-
*/
|
|
12
1
|
export const createDOMContext = () => {
|
|
13
2
|
const setMeta = (name, content) => {
|
|
14
3
|
if (typeof document === "undefined")
|
|
@@ -19,8 +8,6 @@ export const createDOMContext = () => {
|
|
|
19
8
|
?? document.querySelector(`meta[property="${name}"]`);
|
|
20
9
|
if (!element) {
|
|
21
10
|
element = document.createElement("meta");
|
|
22
|
-
// Decide whether the tag uses name= or property= based on the prefix
|
|
23
|
-
// so a single API works for both classic <meta name> and OG <meta property>.
|
|
24
11
|
if (name.startsWith("og:") || name.startsWith("article:") || name.startsWith("profile:") || name.startsWith("music:") || name.startsWith("product:")) {
|
|
25
12
|
element.setAttribute("property", name);
|
|
26
13
|
}
|
|
@@ -38,7 +25,6 @@ export const createDOMContext = () => {
|
|
|
38
25
|
const rel = attrs.rel;
|
|
39
26
|
if (!rel)
|
|
40
27
|
return;
|
|
41
|
-
// Build a precise selector so we replace only the matching node.
|
|
42
28
|
const parts = [`link[rel="${rel}"]`];
|
|
43
29
|
if (attrs.href)
|
|
44
30
|
parts.push(`[href="${attrs.href}"]`);
|
|
@@ -58,5 +44,19 @@ export const createDOMContext = () => {
|
|
|
58
44
|
element.setAttribute(key, value);
|
|
59
45
|
}
|
|
60
46
|
};
|
|
61
|
-
|
|
47
|
+
const setJsonLd = (data) => {
|
|
48
|
+
if (typeof document === "undefined")
|
|
49
|
+
return;
|
|
50
|
+
document
|
|
51
|
+
.querySelectorAll('script[type="application/ld+json"][data-seo="true"]')
|
|
52
|
+
.forEach((el) => el.remove());
|
|
53
|
+
for (const item of data) {
|
|
54
|
+
const script = document.createElement("script");
|
|
55
|
+
script.type = "application/ld+json";
|
|
56
|
+
script.setAttribute("data-seo", "true");
|
|
57
|
+
script.textContent = JSON.stringify(item);
|
|
58
|
+
document.head.appendChild(script);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
return { setMeta, setLink, setJsonLd };
|
|
62
62
|
};
|
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOM mutator.
|
|
3
|
-
*
|
|
4
|
-
* Public entry point for applying SEO options to the live DOM. All work
|
|
5
|
-
* is delegated to the strategy registry; this file is just a thin
|
|
6
|
-
* orchestrator + the few operations that don't fit the Strategy shape
|
|
7
|
-
* (clear, snapshot).
|
|
8
|
-
*/
|
|
9
1
|
import type { LinkTag, MetaTag, SEOptions } from "../../types/index.js";
|
|
10
|
-
/**
|
|
11
|
-
* Apply SEO options to the live DOM.
|
|
12
|
-
*
|
|
13
|
-
* Mutations are batched in a single requestAnimationFrame pass to avoid
|
|
14
|
-
* layout thrashing and to give us a single try/catch boundary.
|
|
15
|
-
*/
|
|
16
2
|
export declare const updateSEO: (options: SEOptions) => void;
|
|
17
|
-
/**
|
|
18
|
-
* Remove every node the library has injected and reset the document title.
|
|
19
|
-
* Useful for tests, SPAs that swap the entire head, or "reset" buttons.
|
|
20
|
-
*/
|
|
21
3
|
export declare const clearSEO: () => void;
|
|
22
|
-
/**
|
|
23
|
-
* Snapshot the current SEO-relevant head into a plain object.
|
|
24
|
-
* Mostly useful for tests and SSR hydration debugging.
|
|
25
|
-
*/
|
|
26
4
|
export declare const getCurrentSEOState: () => {
|
|
27
5
|
title: string;
|
|
28
6
|
lang: string;
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOM mutator.
|
|
3
|
-
*
|
|
4
|
-
* Public entry point for applying SEO options to the live DOM. All work
|
|
5
|
-
* is delegated to the strategy registry; this file is just a thin
|
|
6
|
-
* orchestrator + the few operations that don't fit the Strategy shape
|
|
7
|
-
* (clear, snapshot).
|
|
8
|
-
*/
|
|
9
1
|
import { queueDOMUpdate } from "../../core/dom-queue.js";
|
|
10
2
|
import { SEO_STRATEGIES } from "../../core/seo-strategies.js";
|
|
11
3
|
import { createDOMContext } from "./dom-context.js";
|
|
12
|
-
/**
|
|
13
|
-
* Apply SEO options to the live DOM.
|
|
14
|
-
*
|
|
15
|
-
* Mutations are batched in a single requestAnimationFrame pass to avoid
|
|
16
|
-
* layout thrashing and to give us a single try/catch boundary.
|
|
17
|
-
*/
|
|
18
4
|
export const updateSEO = (options) => {
|
|
19
5
|
if (typeof document === "undefined")
|
|
20
6
|
return;
|
|
@@ -27,29 +13,19 @@ export const updateSEO = (options) => {
|
|
|
27
13
|
strategy.applyDOM(options, ctx);
|
|
28
14
|
}
|
|
29
15
|
catch (error) {
|
|
30
|
-
// Surface strategy failures: the DOM is left in whatever state the
|
|
31
|
-
// previous strategy achieved, but that's recoverable on the next
|
|
32
|
-
// render. Silently swallowing would be much worse.
|
|
33
16
|
console.error(`[SEO] Strategy "${strategy.id}" failed:`, error);
|
|
34
17
|
}
|
|
35
18
|
}
|
|
36
19
|
});
|
|
37
20
|
};
|
|
38
|
-
/**
|
|
39
|
-
* Remove every node the library has injected and reset the document title.
|
|
40
|
-
* Useful for tests, SPAs that swap the entire head, or "reset" buttons.
|
|
41
|
-
*/
|
|
42
21
|
export const clearSEO = () => {
|
|
43
22
|
if (typeof document === "undefined")
|
|
44
23
|
return;
|
|
45
24
|
document.querySelectorAll('meta[data-seo="true"]').forEach((el) => el.remove());
|
|
46
25
|
document.querySelectorAll('link[data-seo="true"]').forEach((el) => el.remove());
|
|
26
|
+
document.querySelectorAll('script[type="application/ld+json"][data-seo="true"]').forEach((el) => el.remove());
|
|
47
27
|
document.title = "";
|
|
48
28
|
};
|
|
49
|
-
/**
|
|
50
|
-
* Snapshot the current SEO-relevant head into a plain object.
|
|
51
|
-
* Mostly useful for tests and SSR hydration debugging.
|
|
52
|
-
*/
|
|
53
29
|
export const getCurrentSEOState = () => {
|
|
54
30
|
if (typeof document === "undefined")
|
|
55
31
|
return null;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO Utils
|
|
3
|
-
*
|
|
4
|
-
* Public utility surface for SEO management.
|
|
5
|
-
*/
|
|
6
1
|
export { updateSEO, clearSEO, getCurrentSEOState } from "./dom/index.js";
|
|
7
2
|
export { generateArticleSchema, generateProductSchema, generateOrganizationSchema, generateLocalBusinessSchema, generateBreadcrumbSchema, generateFAQSchema, generateWebSiteSchema, generatePersonSchema, generateVideoSchema, } from "./schema-generators/index.js";
|
|
8
3
|
export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry, truncateToTitle, truncateToDescription, generateSlug, } from "./validation/index.js";
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO Utils
|
|
3
|
-
*
|
|
4
|
-
* Public utility surface for SEO management.
|
|
5
|
-
*/
|
|
6
|
-
// Core DOM operations
|
|
7
1
|
export { updateSEO, clearSEO, getCurrentSEOState } from "./dom/index.js";
|
|
8
|
-
// Schema generators
|
|
9
2
|
export { generateArticleSchema, generateProductSchema, generateOrganizationSchema, generateLocalBusinessSchema, generateBreadcrumbSchema, generateFAQSchema, generateWebSiteSchema, generatePersonSchema, generateVideoSchema, } from "./schema-generators/index.js";
|
|
10
|
-
// Validators
|
|
11
3
|
export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry, truncateToTitle, truncateToDescription, generateSlug, } from "./validation/index.js";
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema generator base (Template Method).
|
|
3
|
-
*
|
|
4
|
-
* Each generator runs the same flow:
|
|
5
|
-
* 1. Validate required fields (warn in non-strict, throw in strict).
|
|
6
|
-
* 2. Build the schema body.
|
|
7
|
-
* 3. Return the assembled JSON-LD object.
|
|
8
|
-
*
|
|
9
|
-
* `buildSchema` wraps that flow so individual generators can focus on
|
|
10
|
-
* the schema body that actually differs between types.
|
|
11
|
-
*/
|
|
12
1
|
import type { SchemaGeneratorOptions } from "../../types/schema.js";
|
|
13
2
|
type RequiredField = string | number | boolean | object | null | undefined;
|
|
14
3
|
export declare const validateRequired: (value: RequiredField, fieldName: string, strict?: boolean) => void;
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema generator base (Template Method).
|
|
3
|
-
*
|
|
4
|
-
* Each generator runs the same flow:
|
|
5
|
-
* 1. Validate required fields (warn in non-strict, throw in strict).
|
|
6
|
-
* 2. Build the schema body.
|
|
7
|
-
* 3. Return the assembled JSON-LD object.
|
|
8
|
-
*
|
|
9
|
-
* `buildSchema` wraps that flow so individual generators can focus on
|
|
10
|
-
* the schema body that actually differs between types.
|
|
11
|
-
*/
|
|
12
1
|
import { SCHEMA_CONTEXT } from "../../core/constants.js";
|
|
13
2
|
const isMissing = (value) => {
|
|
14
3
|
if (value === null || value === undefined)
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema generator factory.
|
|
3
|
-
*
|
|
4
|
-
* Lets callers dispatch on `@type` instead of remembering each generator
|
|
5
|
-
* function name. Useful for plugins or frameworks that build schemas
|
|
6
|
-
* dynamically from a config object.
|
|
7
|
-
*/
|
|
8
1
|
import type { JsonLdTypes, SchemaGeneratorOptions } from "../../types/schema.js";
|
|
9
2
|
import type { ArticleSchemaInput } from "./types.js";
|
|
10
3
|
import type { FAQItemInput } from "./types.js";
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema generator factory.
|
|
3
|
-
*
|
|
4
|
-
* Lets callers dispatch on `@type` instead of remembering each generator
|
|
5
|
-
* function name. Useful for plugins or frameworks that build schemas
|
|
6
|
-
* dynamically from a config object.
|
|
7
|
-
*/
|
|
8
1
|
import { generateArticleSchema } from "./generators/article.js";
|
|
9
2
|
import { generateBreadcrumbSchema } from "./generators/breadcrumb.js";
|
|
10
3
|
import { generateFAQSchema } from "./generators/faq.js";
|
|
@@ -9,7 +9,7 @@ export const generateArticleSchema = createBuilder((input, ctx) => {
|
|
|
9
9
|
ctx.set(withContext(input.type ?? "Article"));
|
|
10
10
|
ctx.set({
|
|
11
11
|
headline: input.headline,
|
|
12
|
-
name: input.headline,
|
|
12
|
+
name: input.headline,
|
|
13
13
|
description: input.description,
|
|
14
14
|
image: input.image,
|
|
15
15
|
datePublished: input.datePublished,
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema.org Generators
|
|
3
|
-
*
|
|
4
|
-
* Public surface for structured-data generation. One file per generator
|
|
5
|
-
* (see ./generators/*) plus a factory for dynamic dispatch.
|
|
6
|
-
*/
|
|
7
1
|
export { generateArticleSchema } from "./generators/article.js";
|
|
8
2
|
export { generateProductSchema } from "./generators/product.js";
|
|
9
3
|
export { generateOrganizationSchema } from "./generators/organization.js";
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema.org Generators
|
|
3
|
-
*
|
|
4
|
-
* Public surface for structured-data generation. One file per generator
|
|
5
|
-
* (see ./generators/*) plus a factory for dynamic dispatch.
|
|
6
|
-
*/
|
|
7
1
|
export { generateArticleSchema } from "./generators/article.js";
|
|
8
2
|
export { generateProductSchema } from "./generators/product.js";
|
|
9
3
|
export { generateOrganizationSchema } from "./generators/organization.js";
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Open Graph image validation.
|
|
3
|
-
*
|
|
4
|
-
* All four parameters are optional so callers can progressively validate
|
|
5
|
-
* as soon as they know each value.
|
|
6
|
-
*/
|
|
7
1
|
export declare const validateOpenGraphImage: (imageUrl: string, width?: number, height?: number, size?: number) => string | null;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Open Graph image validation.
|
|
3
|
-
*
|
|
4
|
-
* All four parameters are optional so callers can progressively validate
|
|
5
|
-
* as soon as they know each value.
|
|
6
|
-
*/
|
|
7
1
|
import { OG_IMAGE_MAX_SIZE, OG_IMAGE_MIN_HEIGHT, OG_IMAGE_MIN_WIDTH, } from "../../core/constants.js";
|
|
8
2
|
import { isValidUrl } from "./url-validator.js";
|
|
9
3
|
export const validateOpenGraphImage = (imageUrl, width, height, size) => {
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO Validators
|
|
3
|
-
*
|
|
4
|
-
* Validation utilities, organized by concern. Each submodule is a small,
|
|
5
|
-
* focused unit so consumers can pull in only what they need.
|
|
6
|
-
*/
|
|
7
1
|
export { isValidUrl, validateUrl } from "./url-validator.js";
|
|
8
2
|
export { isValidLanguageCode } from "./language-code.js";
|
|
9
3
|
export { validateTitleLength, validateDescriptionLength, truncateToTitle, truncateToDescription, } from "./length-validator.js";
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO Validators
|
|
3
|
-
*
|
|
4
|
-
* Validation utilities, organized by concern. Each submodule is a small,
|
|
5
|
-
* focused unit so consumers can pull in only what they need.
|
|
6
|
-
*/
|
|
7
1
|
export { isValidUrl, validateUrl } from "./url-validator.js";
|
|
8
2
|
export { isValidLanguageCode } from "./language-code.js";
|
|
9
3
|
export { validateTitleLength, validateDescriptionLength, truncateToTitle, truncateToDescription, } from "./length-validator.js";
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON-LD payload validation.
|
|
3
|
-
*
|
|
4
|
-
* Each Schema.org type has its own set of required fields. We use a
|
|
5
|
-
* small type-specific validator per `@type` rather than a giant switch
|
|
6
|
-
* to keep each branch easy to extend.
|
|
7
|
-
*/
|
|
8
1
|
import type { JsonLdTypes } from "../../types/schema.js";
|
|
9
2
|
export declare const validateJsonLd: (jsonLd: JsonLdTypes) => string[];
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON-LD payload validation.
|
|
3
|
-
*
|
|
4
|
-
* Each Schema.org type has its own set of required fields. We use a
|
|
5
|
-
* small type-specific validator per `@type` rather than a giant switch
|
|
6
|
-
* to keep each branch easy to extend.
|
|
7
|
-
*/
|
|
8
1
|
const has = (obj, key) => {
|
|
9
2
|
const value = obj[key];
|
|
10
3
|
if (Array.isArray(value))
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BCP-47 language code validation.
|
|
3
|
-
*
|
|
4
|
-
* Accepts ISO 639-1/2/3 codes with an optional region (e.g. `en`, `en-US`)
|
|
5
|
-
* and the special `x-default` value used by hreflang.
|
|
6
|
-
*/
|
|
7
1
|
const LANG_CODE_REGEX = /^(?:[a-z]{2,3}(?:-[A-Z]{2})?|x-default)$/;
|
|
8
2
|
export const isValidLanguageCode = (code) => LANG_CODE_REGEX.test(code);
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Title and description length validation + truncation helpers.
|
|
3
|
-
*
|
|
4
|
-
* Bounds are exported from `core/constants` so all SEO concerns agree on
|
|
5
|
-
* the recommended ranges.
|
|
6
|
-
*/
|
|
7
1
|
export declare const validateTitleLength: (title: string) => string | null;
|
|
8
2
|
export declare const validateDescriptionLength: (description: string) => string | null;
|
|
9
3
|
export declare const truncateToTitle: (text: string) => string;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Title and description length validation + truncation helpers.
|
|
3
|
-
*
|
|
4
|
-
* Bounds are exported from `core/constants` so all SEO concerns agree on
|
|
5
|
-
* the recommended ranges.
|
|
6
|
-
*/
|
|
7
1
|
import { DESCRIPTION_MAX_LENGTH, DESCRIPTION_MIN_LENGTH, TITLE_MAX_LENGTH, TITLE_MIN_LENGTH, } from "../../core/constants.js";
|
|
8
2
|
const ELLIPSIS = "...";
|
|
9
3
|
export const validateTitleLength = (title) => {
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Comprehensive SEO validation and audit.
|
|
3
|
-
*
|
|
4
|
-
* `validateSEO` returns a structured result; `auditSEO` adds a dev-friendly
|
|
5
|
-
* console summary. Neither mutates inputs.
|
|
6
|
-
*/
|
|
7
1
|
import type { SEOValidationResult, SEOptions } from "../../types/index.js";
|
|
8
2
|
export declare const validateSEO: (options: SEOptions) => SEOValidationResult;
|
|
9
|
-
/**
|
|
10
|
-
* Validate SEO options and print a human-readable report to the console.
|
|
11
|
-
* Opt-in: pass `enableConsole: true` to actually log.
|
|
12
|
-
*
|
|
13
|
-
* Browser-safe: does not read `process.env` (which is undefined in some
|
|
14
|
-
* browser bundles). Use Vite's `import.meta.env.DEV` or a build-time
|
|
15
|
-
* constant if you want dev-only output.
|
|
16
|
-
*/
|
|
17
3
|
export declare const auditSEO: (options: SEOptions, enableConsole?: boolean) => SEOValidationResult;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Comprehensive SEO validation and audit.
|
|
3
|
-
*
|
|
4
|
-
* `validateSEO` returns a structured result; `auditSEO` adds a dev-friendly
|
|
5
|
-
* console summary. Neither mutates inputs.
|
|
6
|
-
*/
|
|
7
1
|
import { validateHreflangEntry } from "./hreflang-validator.js";
|
|
8
2
|
import { validateOpenGraphImage } from "./image-validator.js";
|
|
9
3
|
import { validateDescriptionLength, validateTitleLength } from "./length-validator.js";
|
|
@@ -13,7 +7,6 @@ export const validateSEO = (options) => {
|
|
|
13
7
|
const errors = [];
|
|
14
8
|
const warnings = [];
|
|
15
9
|
const suggestions = [];
|
|
16
|
-
// Title
|
|
17
10
|
if (options.title) {
|
|
18
11
|
const error = validateTitleLength(options.title);
|
|
19
12
|
if (error)
|
|
@@ -22,7 +15,6 @@ export const validateSEO = (options) => {
|
|
|
22
15
|
else {
|
|
23
16
|
errors.push("Title is missing");
|
|
24
17
|
}
|
|
25
|
-
// Description
|
|
26
18
|
if (options.description) {
|
|
27
19
|
const error = validateDescriptionLength(options.description);
|
|
28
20
|
if (error)
|
|
@@ -31,7 +23,6 @@ export const validateSEO = (options) => {
|
|
|
31
23
|
else {
|
|
32
24
|
warnings.push("Description is missing");
|
|
33
25
|
}
|
|
34
|
-
// Canonical
|
|
35
26
|
if (options.canonical) {
|
|
36
27
|
const error = validateUrl(options.canonical, "Canonical URL");
|
|
37
28
|
if (error)
|
|
@@ -40,12 +31,10 @@ export const validateSEO = (options) => {
|
|
|
40
31
|
else {
|
|
41
32
|
suggestions.push("Add a canonical URL to prevent duplicate content issues");
|
|
42
33
|
}
|
|
43
|
-
// Language
|
|
44
34
|
if (!options.lang) {
|
|
45
35
|
warnings.push("Language attribute is missing");
|
|
46
36
|
suggestions.push('Add lang attribute (e.g., <html lang="en">)');
|
|
47
37
|
}
|
|
48
|
-
// Open Graph
|
|
49
38
|
if (!options.openGraph) {
|
|
50
39
|
suggestions.push("Add Open Graph tags for better social media sharing");
|
|
51
40
|
}
|
|
@@ -60,11 +49,9 @@ export const validateSEO = (options) => {
|
|
|
60
49
|
if (imageError)
|
|
61
50
|
warnings.push(imageError);
|
|
62
51
|
}
|
|
63
|
-
// Twitter
|
|
64
52
|
if (!options.twitter) {
|
|
65
53
|
suggestions.push("Add Twitter Card tags for better Twitter sharing");
|
|
66
54
|
}
|
|
67
|
-
// Hreflang
|
|
68
55
|
if (options.hreflang && options.hreflang.length > 0) {
|
|
69
56
|
options.hreflang.forEach((entry, index) => {
|
|
70
57
|
const error = validateHreflangEntry(entry);
|
|
@@ -75,7 +62,6 @@ export const validateSEO = (options) => {
|
|
|
75
62
|
suggestions.push('Add hreflang="x-default" for language fallback');
|
|
76
63
|
}
|
|
77
64
|
}
|
|
78
|
-
// JSON-LD
|
|
79
65
|
if (options.jsonLd && options.jsonLd.length > 0) {
|
|
80
66
|
options.jsonLd.forEach((data, index) => {
|
|
81
67
|
validateJsonLd(data).forEach((error) => {
|
|
@@ -86,14 +72,12 @@ export const validateSEO = (options) => {
|
|
|
86
72
|
else {
|
|
87
73
|
suggestions.push("Add JSON-LD structured data for rich snippets in search results");
|
|
88
74
|
}
|
|
89
|
-
// Favicon + theme color
|
|
90
75
|
if (!options.favicon) {
|
|
91
76
|
suggestions.push("Add a favicon for better brand recognition in browser tabs");
|
|
92
77
|
}
|
|
93
78
|
if (!options.themeColor) {
|
|
94
79
|
suggestions.push("Add a theme color for better mobile browser integration");
|
|
95
80
|
}
|
|
96
|
-
// Performance
|
|
97
81
|
if (!options.preconnect || options.preconnect.length === 0) {
|
|
98
82
|
suggestions.push("Add preconnect hints for external resources to improve performance");
|
|
99
83
|
}
|
|
@@ -105,14 +89,6 @@ const STYLE = {
|
|
|
105
89
|
success: "color: #388e3c; font-weight: bold;",
|
|
106
90
|
info: "color: #1976d2; font-weight: bold;",
|
|
107
91
|
};
|
|
108
|
-
/**
|
|
109
|
-
* Validate SEO options and print a human-readable report to the console.
|
|
110
|
-
* Opt-in: pass `enableConsole: true` to actually log.
|
|
111
|
-
*
|
|
112
|
-
* Browser-safe: does not read `process.env` (which is undefined in some
|
|
113
|
-
* browser bundles). Use Vite's `import.meta.env.DEV` or a build-time
|
|
114
|
-
* constant if you want dev-only output.
|
|
115
|
-
*/
|
|
116
92
|
export const auditSEO = (options, enableConsole = true) => {
|
|
117
93
|
const result = validateSEO(options);
|
|
118
94
|
if (!enableConsole || typeof console === "undefined")
|