@umituz/web-seo 2.0.21 → 2.1.1
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 +1 -9
- package/dist/domains/seo/components/JsonLd.js +22 -80
- package/dist/domains/seo/components/SEO.js +5 -35
- 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 +9 -0
- package/dist/domains/seo/core/constants.js +9 -0
- package/dist/domains/seo/core/deep-equal.d.ts +1 -0
- package/dist/domains/seo/core/deep-equal.js +21 -0
- package/dist/domains/seo/core/dom-queue.d.ts +3 -0
- package/dist/domains/seo/core/dom-queue.js +27 -0
- package/dist/domains/seo/core/escape.d.ts +2 -0
- package/dist/domains/seo/core/escape.js +31 -0
- package/dist/domains/seo/core/hash.d.ts +1 -0
- package/dist/domains/seo/core/hash.js +21 -0
- package/dist/domains/seo/core/init.d.ts +4 -2
- package/dist/domains/seo/core/init.js +27 -18
- package/dist/domains/seo/core/seo-strategies.d.ts +19 -0
- package/dist/domains/seo/core/seo-strategies.js +620 -0
- package/dist/domains/seo/core/seo-strategy.d.ts +16 -0
- package/dist/domains/seo/core/seo-strategy.js +1 -0
- 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 +2 -10
- package/dist/domains/seo/hooks/useJsonLd.js +23 -64
- package/dist/domains/seo/hooks/useSEO.js +2 -30
- package/dist/domains/seo/ssr/helmet.d.ts +18 -0
- package/dist/domains/seo/ssr/helmet.js +16 -0
- package/dist/domains/seo/ssr/index.d.ts +5 -0
- package/dist/domains/seo/ssr/index.js +3 -0
- package/dist/domains/seo/ssr/renderer.d.ts +1 -47
- package/dist/domains/seo/ssr/renderer.js +41 -296
- package/dist/domains/seo/ssr/serializer.d.ts +0 -66
- package/dist/domains/seo/ssr/serializer.js +21 -172
- package/dist/domains/seo/types/index.d.ts +0 -4
- package/dist/domains/seo/types/schema.d.ts +22 -3
- package/dist/domains/seo/types/schema.js +0 -3
- package/dist/domains/seo/utils/dom/dom-context.d.ts +2 -0
- package/dist/domains/seo/utils/dom/dom-context.js +48 -0
- package/dist/domains/seo/utils/dom/dom-mutator.d.ts +9 -0
- package/dist/domains/seo/utils/dom/dom-mutator.js +64 -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 +2 -8
- package/dist/domains/seo/utils/index.js +2 -12
- package/dist/domains/seo/utils/schema-generators/base.d.ts +14 -0
- package/dist/domains/seo/utils/schema-generators/base.js +39 -0
- package/dist/domains/seo/utils/schema-generators/factory.d.ts +20 -0
- package/dist/domains/seo/utils/schema-generators/factory.js +42 -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 +13 -6
- package/dist/domains/seo/utils/schema-generators/index.js +11 -6
- package/dist/domains/seo/utils/schema-generators/types.d.ts +138 -0
- package/dist/domains/seo/utils/schema-generators/types.js +1 -0
- package/dist/domains/seo/utils/validation/hreflang-validator.d.ts +4 -0
- package/dist/domains/seo/utils/validation/hreflang-validator.js +10 -0
- package/dist/domains/seo/utils/validation/image-validator.d.ts +1 -0
- package/dist/domains/seo/utils/validation/image-validator.js +18 -0
- package/dist/domains/seo/utils/validation/index.d.ts +8 -6
- package/dist/domains/seo/utils/validation/index.js +8 -6
- package/dist/domains/seo/utils/validation/jsonld-validator.d.ts +2 -0
- package/dist/domains/seo/utils/validation/jsonld-validator.js +67 -0
- package/dist/domains/seo/utils/validation/language-code.d.ts +1 -0
- package/dist/domains/seo/utils/validation/language-code.js +2 -0
- package/dist/domains/seo/utils/validation/length-validator.d.ts +4 -0
- package/dist/domains/seo/utils/validation/length-validator.js +34 -0
- package/dist/domains/seo/utils/validation/seo-auditor.d.ts +3 -0
- package/dist/domains/seo/utils/validation/seo-auditor.js +120 -0
- package/dist/domains/seo/utils/validation/text-helpers.d.ts +1 -0
- package/dist/domains/seo/utils/validation/text-helpers.js +6 -0
- package/dist/domains/seo/utils/validation/url-validator.d.ts +2 -0
- package/dist/domains/seo/utils/validation/url-validator.js +20 -0
- package/dist/domains/seo/vite/index.d.ts +3 -7
- package/dist/domains/seo/vite/index.js +2 -6
- package/dist/domains/seo/vite/plugin.d.ts +1 -59
- package/dist/domains/seo/vite/plugin.js +26 -190
- package/dist/domains/seo/vite/presets.d.ts +8 -0
- package/dist/domains/seo/vite/presets.js +28 -0
- package/dist/domains/seo/vite/robots-generator.d.ts +6 -0
- package/dist/domains/seo/vite/robots-generator.js +33 -0
- package/dist/domains/seo/vite/sitemap-generator.d.ts +8 -0
- package/dist/domains/seo/vite/sitemap-generator.js +49 -0
- package/dist/domains/seo/vite/types.d.ts +20 -0
- package/dist/domains/seo/vite/types.js +1 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.js +4 -12
- package/package.json +1 -1
|
@@ -1,72 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SEO Serializer
|
|
3
|
-
*
|
|
4
|
-
* Serialization utilities for SEO data.
|
|
5
|
-
* Used for server-side rendering and hydration.
|
|
6
|
-
*/
|
|
7
1
|
import type { SEOptions } from "../types/index.js";
|
|
8
|
-
/**
|
|
9
|
-
* Serialize SEO options to a string for transmission/hydration
|
|
10
|
-
*/
|
|
11
2
|
export declare const serializeSEO: (options: SEOptions) => string;
|
|
12
|
-
/**
|
|
13
|
-
* Deserialize SEO options from a string
|
|
14
|
-
* @throws {SyntaxError} If data is not valid JSON
|
|
15
|
-
*/
|
|
16
3
|
export declare const deserializeSEO: (data: string) => SEOptions;
|
|
17
|
-
/**
|
|
18
|
-
* Serialize SEO options to base64 for safe URL transmission
|
|
19
|
-
*/
|
|
20
4
|
export declare const serializeSEOToBase64: (options: SEOptions) => string;
|
|
21
|
-
/**
|
|
22
|
-
* Deserialize SEO options from base64
|
|
23
|
-
*/
|
|
24
5
|
export declare const deserializeSEOFromBase64: (base64: string) => SEOptions;
|
|
25
|
-
interface SEOState {
|
|
26
|
-
options: SEOptions;
|
|
27
|
-
timestamp: number;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Create SEO state with timestamp
|
|
31
|
-
*/
|
|
32
|
-
export declare const createSEOState: (options: SEOptions) => SEOState;
|
|
33
|
-
/**
|
|
34
|
-
* Serialize SEO state
|
|
35
|
-
*/
|
|
36
|
-
export declare const serializeSEOState: (state: SEOState) => string;
|
|
37
|
-
/**
|
|
38
|
-
* Deserialize SEO state
|
|
39
|
-
* @throws {SyntaxError} If data is not valid JSON
|
|
40
|
-
*/
|
|
41
|
-
export declare const deserializeSEOState: (data: string) => SEOState;
|
|
42
|
-
/**
|
|
43
|
-
* Check if SEO state is stale (older than specified milliseconds)
|
|
44
|
-
*/
|
|
45
|
-
export declare const isSEOStateStale: (state: SEOState, maxAge?: number) => boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Compress SEO options using simple compression
|
|
48
|
-
* Removes undefined values and empty arrays
|
|
49
|
-
*/
|
|
50
|
-
export declare const compressSEO: (options: SEOptions) => SEOptions;
|
|
51
|
-
/**
|
|
52
|
-
* Decompress SEO options (identity function, kept for API consistency)
|
|
53
|
-
*/
|
|
54
|
-
export declare const decompressSEO: (options: SEOptions) => SEOptions;
|
|
55
|
-
/**
|
|
56
|
-
* Serialize SEO options to URL-safe query string
|
|
57
|
-
* Only includes essential SEO data for social sharing previews
|
|
58
|
-
*/
|
|
59
|
-
export declare const serializeSEOToQueryString: (options: SEOptions) => string;
|
|
60
|
-
/**
|
|
61
|
-
* Deserialize SEO options from query string
|
|
62
|
-
*/
|
|
63
|
-
export declare const deserializeSEOFromQueryString: (queryString: string) => Partial<SEOptions>;
|
|
64
|
-
/**
|
|
65
|
-
* Validate serialized SEO data before deserialization
|
|
66
|
-
*/
|
|
67
|
-
export declare const validateSerializedSEO: (data: string) => boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Safe deserialize with validation
|
|
70
|
-
*/
|
|
71
6
|
export declare const safeDeserializeSEO: (data: string) => SEOptions | null;
|
|
72
|
-
export {};
|
|
@@ -1,191 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
* SEO Serializer
|
|
3
|
-
*
|
|
4
|
-
* Serialization utilities for SEO data.
|
|
5
|
-
* Used for server-side rendering and hydration.
|
|
6
|
-
*/
|
|
7
|
-
// ============================================================================
|
|
8
|
-
// Serialization
|
|
9
|
-
// ============================================================================
|
|
10
|
-
/**
|
|
11
|
-
* Serialize SEO options to a string for transmission/hydration
|
|
12
|
-
*/
|
|
13
|
-
export const serializeSEO = (options) => {
|
|
14
|
-
return JSON.stringify(options);
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Deserialize SEO options from a string
|
|
18
|
-
* @throws {SyntaxError} If data is not valid JSON
|
|
19
|
-
*/
|
|
1
|
+
export const serializeSEO = (options) => JSON.stringify(options);
|
|
20
2
|
export const deserializeSEO = (data) => {
|
|
21
3
|
try {
|
|
22
4
|
return JSON.parse(data);
|
|
23
5
|
}
|
|
24
6
|
catch (error) {
|
|
25
|
-
|
|
7
|
+
const reason = error instanceof Error ? error.message : "Unknown error";
|
|
8
|
+
throw new Error(`[SEO] Failed to deserialize SEO data: ${reason}`);
|
|
26
9
|
}
|
|
27
10
|
};
|
|
28
|
-
|
|
29
|
-
* Serialize SEO options to base64 for safe URL transmission
|
|
30
|
-
*/
|
|
31
|
-
export const serializeSEOToBase64 = (options) => {
|
|
32
|
-
const json = serializeSEO(options);
|
|
11
|
+
const toBase64 = (json) => {
|
|
33
12
|
if (typeof Buffer !== "undefined") {
|
|
34
13
|
return Buffer.from(json).toString("base64");
|
|
35
14
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const binaryString = Array.from(utf8Bytes, (byte) => String.fromCharCode(byte)).join("");
|
|
39
|
-
return btoa(binaryString);
|
|
15
|
+
const bytes = new TextEncoder().encode(json);
|
|
16
|
+
return btoa(Array.from(bytes, (b) => String.fromCharCode(b)).join(""));
|
|
40
17
|
};
|
|
41
|
-
|
|
42
|
-
* Deserialize SEO options from base64
|
|
43
|
-
*/
|
|
44
|
-
export const deserializeSEOFromBase64 = (base64) => {
|
|
45
|
-
let json;
|
|
18
|
+
const fromBase64 = (base64) => {
|
|
46
19
|
if (typeof Buffer !== "undefined") {
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
// Browser fallback with UTF-8 support
|
|
51
|
-
const binaryString = atob(base64);
|
|
52
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
53
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
54
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
55
|
-
}
|
|
56
|
-
json = new TextDecoder().decode(bytes);
|
|
57
|
-
}
|
|
58
|
-
return deserializeSEO(json);
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Create SEO state with timestamp
|
|
62
|
-
*/
|
|
63
|
-
export const createSEOState = (options) => {
|
|
64
|
-
return {
|
|
65
|
-
options,
|
|
66
|
-
timestamp: Date.now(),
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Serialize SEO state
|
|
71
|
-
*/
|
|
72
|
-
export const serializeSEOState = (state) => {
|
|
73
|
-
return JSON.stringify(state);
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Deserialize SEO state
|
|
77
|
-
* @throws {SyntaxError} If data is not valid JSON
|
|
78
|
-
*/
|
|
79
|
-
export const deserializeSEOState = (data) => {
|
|
80
|
-
try {
|
|
81
|
-
return JSON.parse(data);
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
throw new Error(`[SEO] Failed to deserialize SEO state: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Check if SEO state is stale (older than specified milliseconds)
|
|
89
|
-
*/
|
|
90
|
-
export const isSEOStateStale = (state, maxAge = 3600000) => {
|
|
91
|
-
return Date.now() - state.timestamp > maxAge;
|
|
92
|
-
};
|
|
93
|
-
// ============================================================================
|
|
94
|
-
// Compression (for large SEO datasets)
|
|
95
|
-
// ============================================================================
|
|
96
|
-
/**
|
|
97
|
-
* Compress SEO options using simple compression
|
|
98
|
-
* Removes undefined values and empty arrays
|
|
99
|
-
*/
|
|
100
|
-
export const compressSEO = (options) => {
|
|
101
|
-
const compressed = {};
|
|
102
|
-
Object.entries(options).forEach(([key, value]) => {
|
|
103
|
-
if (value === undefined || (Array.isArray(value) && value.length === 0)) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
// Compress nested objects
|
|
107
|
-
if (typeof value === "object" && !Array.isArray(value)) {
|
|
108
|
-
const compressedNested = compressSEO(value);
|
|
109
|
-
if (Object.keys(compressedNested).length > 0) {
|
|
110
|
-
compressed[key] = compressedNested;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
compressed[key] = value;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
return compressed;
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Decompress SEO options (identity function, kept for API consistency)
|
|
121
|
-
*/
|
|
122
|
-
export const decompressSEO = (options) => {
|
|
123
|
-
return options;
|
|
124
|
-
};
|
|
125
|
-
// ============================================================================
|
|
126
|
-
// Query String Serialization
|
|
127
|
-
// ============================================================================
|
|
128
|
-
/**
|
|
129
|
-
* Serialize SEO options to URL-safe query string
|
|
130
|
-
* Only includes essential SEO data for social sharing previews
|
|
131
|
-
*/
|
|
132
|
-
export const serializeSEOToQueryString = (options) => {
|
|
133
|
-
const params = new URLSearchParams();
|
|
134
|
-
if (options.title)
|
|
135
|
-
params.set("title", options.title);
|
|
136
|
-
if (options.description)
|
|
137
|
-
params.set("description", options.description);
|
|
138
|
-
if (options.openGraph?.image) {
|
|
139
|
-
const image = Array.isArray(options.openGraph.image)
|
|
140
|
-
? options.openGraph.image[0]?.url
|
|
141
|
-
: options.openGraph.image;
|
|
142
|
-
if (image)
|
|
143
|
-
params.set("image", image);
|
|
20
|
+
return Buffer.from(base64, "base64").toString("utf-8");
|
|
144
21
|
}
|
|
145
|
-
|
|
22
|
+
const binary = atob(base64);
|
|
23
|
+
const bytes = new Uint8Array(binary.length);
|
|
24
|
+
for (let i = 0; i < binary.length; i++)
|
|
25
|
+
bytes[i] = binary.charCodeAt(i);
|
|
26
|
+
return new TextDecoder().decode(bytes);
|
|
146
27
|
};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
*/
|
|
150
|
-
export const deserializeSEOFromQueryString = (queryString) => {
|
|
151
|
-
const params = new URLSearchParams(queryString);
|
|
152
|
-
const options = {};
|
|
153
|
-
if (params.has("title"))
|
|
154
|
-
options.title = params.get("title");
|
|
155
|
-
if (params.has("description"))
|
|
156
|
-
options.description = params.get("description");
|
|
157
|
-
if (params.has("image")) {
|
|
158
|
-
options.openGraph = {
|
|
159
|
-
image: params.get("image"),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
return options;
|
|
163
|
-
};
|
|
164
|
-
// ============================================================================
|
|
165
|
-
// Validation
|
|
166
|
-
// ============================================================================
|
|
167
|
-
/**
|
|
168
|
-
* Validate serialized SEO data before deserialization
|
|
169
|
-
*/
|
|
170
|
-
export const validateSerializedSEO = (data) => {
|
|
171
|
-
try {
|
|
172
|
-
const parsed = JSON.parse(data);
|
|
173
|
-
return typeof parsed === "object" && parsed !== null;
|
|
174
|
-
}
|
|
175
|
-
catch {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* Safe deserialize with validation
|
|
181
|
-
*/
|
|
28
|
+
export const serializeSEOToBase64 = (options) => toBase64(serializeSEO(options));
|
|
29
|
+
export const deserializeSEOFromBase64 = (base64) => deserializeSEO(fromBase64(base64));
|
|
182
30
|
export const safeDeserializeSEO = (data) => {
|
|
183
|
-
if (!validateSerializedSEO(data)) {
|
|
184
|
-
console.error("[SEO] Invalid serialized data");
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
31
|
try {
|
|
188
|
-
|
|
32
|
+
const parsed = JSON.parse(data);
|
|
33
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
34
|
+
console.error("[SEO] Invalid serialized data: not an object");
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return parsed;
|
|
189
38
|
}
|
|
190
39
|
catch (error) {
|
|
191
40
|
console.error("[SEO] Error deserializing data:", error);
|
|
@@ -15,10 +15,6 @@ export interface LinkTag {
|
|
|
15
15
|
crossOrigin?: string;
|
|
16
16
|
as?: string;
|
|
17
17
|
}
|
|
18
|
-
export interface ScriptTag {
|
|
19
|
-
type: string;
|
|
20
|
-
innerHTML: string;
|
|
21
|
-
}
|
|
22
18
|
export type RobotsDirective = "index" | "noindex" | "follow" | "nofollow" | "noarchive" | "nosnippet" | "notranslate" | "noimageindex" | "unavailable_after";
|
|
23
19
|
export interface RobotsMeta {
|
|
24
20
|
index?: boolean;
|
|
@@ -201,11 +201,30 @@ export interface BookJsonLd extends Thing {
|
|
|
201
201
|
bookFormat?: "AudiobookFormat" | "EBook" | "Hardcover" | "Paperback";
|
|
202
202
|
aggregateRating?: AggregateRating;
|
|
203
203
|
}
|
|
204
|
-
export
|
|
204
|
+
export interface CourseInstance {
|
|
205
|
+
"@type": "CourseInstance";
|
|
206
|
+
courseMode?: "online" | "onsite" | "blended" | string;
|
|
207
|
+
courseWorkload?: string;
|
|
208
|
+
instructor?: PersonOrOrganization;
|
|
209
|
+
inLanguage?: string;
|
|
210
|
+
startDate?: string;
|
|
211
|
+
endDate?: string;
|
|
212
|
+
}
|
|
213
|
+
export interface CourseJsonLd extends Thing {
|
|
214
|
+
"@type": "Course";
|
|
215
|
+
provider: PersonOrOrganization;
|
|
216
|
+
offers?: Offer | Offer[];
|
|
217
|
+
courseCode?: string;
|
|
218
|
+
educationalLevel?: string;
|
|
219
|
+
inLanguage?: string;
|
|
220
|
+
hasCourseInstance?: CourseInstance | CourseInstance[];
|
|
221
|
+
teaches?: string | string[];
|
|
222
|
+
aggregateRating?: AggregateRating;
|
|
223
|
+
review?: Review[];
|
|
224
|
+
}
|
|
225
|
+
export type JsonLdTypes = ArticleJsonLd | ProductJsonLd | OrganizationJsonLd | LocalBusinessJsonLd | BreadcrumbJsonLd | FAQJsonLd | WebSiteJsonLd | PersonJsonLd | VideoJsonLd | AudioJsonLd | BookJsonLd | CourseJsonLd;
|
|
205
226
|
export type SchemaType = JsonLdTypes["@type"];
|
|
206
227
|
export interface SchemaGeneratorOptions {
|
|
207
|
-
/** Strict mode - throws errors instead of warnings */
|
|
208
228
|
strict?: boolean;
|
|
209
|
-
/** Validate generated schema against Schema.org requirements */
|
|
210
229
|
validate?: boolean;
|
|
211
230
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const createDOMContext = () => {
|
|
2
|
+
const setMeta = (name, content) => {
|
|
3
|
+
if (typeof document === "undefined")
|
|
4
|
+
return;
|
|
5
|
+
if (content === undefined)
|
|
6
|
+
return;
|
|
7
|
+
let element = document.querySelector(`meta[name="${name}"]`)
|
|
8
|
+
?? document.querySelector(`meta[property="${name}"]`);
|
|
9
|
+
if (!element) {
|
|
10
|
+
element = document.createElement("meta");
|
|
11
|
+
if (name.startsWith("og:") || name.startsWith("article:") || name.startsWith("profile:") || name.startsWith("music:") || name.startsWith("product:")) {
|
|
12
|
+
element.setAttribute("property", name);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
element.setAttribute("name", name);
|
|
16
|
+
}
|
|
17
|
+
element.setAttribute("data-seo", "true");
|
|
18
|
+
document.head.appendChild(element);
|
|
19
|
+
}
|
|
20
|
+
element.setAttribute("content", content);
|
|
21
|
+
};
|
|
22
|
+
const setLink = (attrs) => {
|
|
23
|
+
if (typeof document === "undefined")
|
|
24
|
+
return;
|
|
25
|
+
const rel = attrs.rel;
|
|
26
|
+
if (!rel)
|
|
27
|
+
return;
|
|
28
|
+
const parts = [`link[rel="${rel}"]`];
|
|
29
|
+
if (attrs.href)
|
|
30
|
+
parts.push(`[href="${attrs.href}"]`);
|
|
31
|
+
if (attrs.sizes)
|
|
32
|
+
parts.push(`[sizes="${attrs.sizes}"]`);
|
|
33
|
+
if (attrs.type)
|
|
34
|
+
parts.push(`[type="${attrs.type}"]`);
|
|
35
|
+
if (attrs.hreflang)
|
|
36
|
+
parts.push(`[hreflang="${attrs.hreflang}"]`);
|
|
37
|
+
let element = document.querySelector(parts.join(""));
|
|
38
|
+
if (!element) {
|
|
39
|
+
element = document.createElement("link");
|
|
40
|
+
element.setAttribute("data-seo", "true");
|
|
41
|
+
document.head.appendChild(element);
|
|
42
|
+
}
|
|
43
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
44
|
+
element.setAttribute(key, value);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return { setMeta, setLink };
|
|
48
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LinkTag, MetaTag, SEOptions } from "../../types/index.js";
|
|
2
|
+
export declare const updateSEO: (options: SEOptions) => void;
|
|
3
|
+
export declare const clearSEO: () => void;
|
|
4
|
+
export declare const getCurrentSEOState: () => {
|
|
5
|
+
title: string;
|
|
6
|
+
lang: string;
|
|
7
|
+
metaTags: MetaTag[];
|
|
8
|
+
linkTags: LinkTag[];
|
|
9
|
+
} | null;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { queueDOMUpdate } from "../../core/dom-queue.js";
|
|
2
|
+
import { SEO_STRATEGIES } from "../../core/seo-strategies.js";
|
|
3
|
+
import { createDOMContext } from "./dom-context.js";
|
|
4
|
+
export const updateSEO = (options) => {
|
|
5
|
+
if (typeof document === "undefined")
|
|
6
|
+
return;
|
|
7
|
+
queueDOMUpdate(() => {
|
|
8
|
+
const ctx = createDOMContext();
|
|
9
|
+
for (const strategy of SEO_STRATEGIES) {
|
|
10
|
+
if (!strategy.applies(options))
|
|
11
|
+
continue;
|
|
12
|
+
try {
|
|
13
|
+
strategy.applyDOM(options, ctx);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.error(`[SEO] Strategy "${strategy.id}" failed:`, error);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const clearSEO = () => {
|
|
22
|
+
if (typeof document === "undefined")
|
|
23
|
+
return;
|
|
24
|
+
document.querySelectorAll('meta[data-seo="true"]').forEach((el) => el.remove());
|
|
25
|
+
document.querySelectorAll('link[data-seo="true"]').forEach((el) => el.remove());
|
|
26
|
+
document.title = "";
|
|
27
|
+
};
|
|
28
|
+
export const getCurrentSEOState = () => {
|
|
29
|
+
if (typeof document === "undefined")
|
|
30
|
+
return null;
|
|
31
|
+
const metaTags = [];
|
|
32
|
+
document.querySelectorAll("meta").forEach((meta) => {
|
|
33
|
+
const name = meta.getAttribute("name");
|
|
34
|
+
const property = meta.getAttribute("property");
|
|
35
|
+
const content = meta.getAttribute("content");
|
|
36
|
+
if (!content)
|
|
37
|
+
return;
|
|
38
|
+
if (name)
|
|
39
|
+
metaTags.push({ name, content });
|
|
40
|
+
else if (property)
|
|
41
|
+
metaTags.push({ property, content });
|
|
42
|
+
});
|
|
43
|
+
const linkTags = [];
|
|
44
|
+
document.querySelectorAll("link").forEach((link) => {
|
|
45
|
+
const rel = link.getAttribute("rel");
|
|
46
|
+
const href = link.getAttribute("href");
|
|
47
|
+
if (!rel || !href)
|
|
48
|
+
return;
|
|
49
|
+
const tag = { rel, href };
|
|
50
|
+
const type = link.getAttribute("type");
|
|
51
|
+
const sizes = link.getAttribute("sizes");
|
|
52
|
+
if (type)
|
|
53
|
+
tag.type = type;
|
|
54
|
+
if (sizes)
|
|
55
|
+
tag.sizes = sizes;
|
|
56
|
+
linkTags.push(tag);
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
title: document.title,
|
|
60
|
+
lang: document.documentElement.lang,
|
|
61
|
+
metaTags,
|
|
62
|
+
linkTags,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { updateSEO, clearSEO, getCurrentSEOState } from "./dom-mutator.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { updateSEO, clearSEO, getCurrentSEOState } from "./dom-mutator.js";
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
* SEO Utils
|
|
3
|
-
*
|
|
4
|
-
* Utility functions for SEO management
|
|
5
|
-
*/
|
|
6
|
-
export { updateSEO, clearSEO, getCurrentSEOState } from "./dom.js";
|
|
7
|
-
export * from "./meta-tags/index.js";
|
|
1
|
+
export { updateSEO, clearSEO, getCurrentSEOState } from "./dom/index.js";
|
|
8
2
|
export { generateArticleSchema, generateProductSchema, generateOrganizationSchema, generateLocalBusinessSchema, generateBreadcrumbSchema, generateFAQSchema, generateWebSiteSchema, generatePersonSchema, generateVideoSchema, } from "./schema-generators/index.js";
|
|
9
|
-
export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry,
|
|
3
|
+
export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry, truncateToTitle, truncateToDescription, generateSlug, } from "./validation/index.js";
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
* SEO Utils
|
|
3
|
-
*
|
|
4
|
-
* Utility functions for SEO management
|
|
5
|
-
*/
|
|
6
|
-
// Core DOM operations
|
|
7
|
-
export { updateSEO, clearSEO, getCurrentSEOState } from "./dom.js";
|
|
8
|
-
// Meta tag utilities
|
|
9
|
-
export * from "./meta-tags/index.js";
|
|
10
|
-
// Schema generators
|
|
1
|
+
export { updateSEO, clearSEO, getCurrentSEOState } from "./dom/index.js";
|
|
11
2
|
export { generateArticleSchema, generateProductSchema, generateOrganizationSchema, generateLocalBusinessSchema, generateBreadcrumbSchema, generateFAQSchema, generateWebSiteSchema, generatePersonSchema, generateVideoSchema, } from "./schema-generators/index.js";
|
|
12
|
-
|
|
13
|
-
export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry, truncateForSEO, generateSlug, } from "./validation/index.js";
|
|
3
|
+
export { validateSEO, auditSEO, isValidUrl, validateUrl, validateTitleLength, validateDescriptionLength, validateOpenGraphImage, validateHreflangEntry, truncateToTitle, truncateToDescription, generateSlug, } from "./validation/index.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SchemaGeneratorOptions } from "../../types/schema.js";
|
|
2
|
+
type RequiredField = string | number | boolean | object | null | undefined;
|
|
3
|
+
export declare const validateRequired: (value: RequiredField, fieldName: string, strict?: boolean) => void;
|
|
4
|
+
export interface BuildContext<T> {
|
|
5
|
+
options: Required<SchemaGeneratorOptions>;
|
|
6
|
+
required(field: RequiredField, name: string): void;
|
|
7
|
+
set(input: Partial<T>): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const createBuilder: <TInput, TOutput>(build: (input: TInput, ctx: BuildContext<TOutput>) => void) => (input: TInput, options?: SchemaGeneratorOptions) => TOutput;
|
|
10
|
+
export declare const withContext: <T extends string>(type: T) => {
|
|
11
|
+
"@context": string;
|
|
12
|
+
"@type": T;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SCHEMA_CONTEXT } from "../../core/constants.js";
|
|
2
|
+
const isMissing = (value) => {
|
|
3
|
+
if (value === null || value === undefined)
|
|
4
|
+
return true;
|
|
5
|
+
if (typeof value === "string")
|
|
6
|
+
return value.length === 0;
|
|
7
|
+
if (Array.isArray(value))
|
|
8
|
+
return value.length === 0;
|
|
9
|
+
return false;
|
|
10
|
+
};
|
|
11
|
+
export const validateRequired = (value, fieldName, strict = false) => {
|
|
12
|
+
if (isMissing(value)) {
|
|
13
|
+
const message = `[SEO] Schema validation: Required field "${fieldName}" is missing or empty`;
|
|
14
|
+
if (strict)
|
|
15
|
+
throw new Error(message);
|
|
16
|
+
console.warn(message);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const createBuilder = (build) => (input, options) => {
|
|
20
|
+
const opts = { strict: false, validate: true, ...options };
|
|
21
|
+
const body = {};
|
|
22
|
+
const ctx = {
|
|
23
|
+
options: opts,
|
|
24
|
+
required(value, name) {
|
|
25
|
+
if (!opts.validate)
|
|
26
|
+
return;
|
|
27
|
+
validateRequired(value, name, opts.strict);
|
|
28
|
+
},
|
|
29
|
+
set(partial) {
|
|
30
|
+
Object.assign(body, partial);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
build(input, ctx);
|
|
34
|
+
return body;
|
|
35
|
+
};
|
|
36
|
+
export const withContext = (type) => ({
|
|
37
|
+
"@context": SCHEMA_CONTEXT,
|
|
38
|
+
"@type": type,
|
|
39
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { JsonLdTypes, SchemaGeneratorOptions } from "../../types/schema.js";
|
|
2
|
+
import type { ArticleSchemaInput } from "./types.js";
|
|
3
|
+
import type { FAQItemInput } from "./types.js";
|
|
4
|
+
import type { LocalBusinessSchemaInput } from "./types.js";
|
|
5
|
+
import type { OrganizationSchemaInput } from "./types.js";
|
|
6
|
+
import type { PersonSchemaInput } from "./types.js";
|
|
7
|
+
import type { ProductSchemaInput } from "./types.js";
|
|
8
|
+
import type { VideoSchemaInput } from "./types.js";
|
|
9
|
+
import type { WebSiteSchemaInput } from "./types.js";
|
|
10
|
+
import type { CourseSchemaInput } from "./types.js";
|
|
11
|
+
export type SchemaKind = "Article" | "NewsArticle" | "BlogPosting" | "Product" | "Organization" | "LocalBusiness" | "BreadcrumbList" | "FAQPage" | "WebSite" | "Person" | "VideoObject" | "Course";
|
|
12
|
+
type GeneratorInput<K extends SchemaKind> = K extends "Article" | "NewsArticle" | "BlogPosting" ? ArticleSchemaInput : K extends "Product" ? ProductSchemaInput : K extends "Organization" ? OrganizationSchemaInput : K extends "LocalBusiness" ? LocalBusinessSchemaInput : K extends "FAQPage" ? FAQItemInput[] : K extends "WebSite" ? WebSiteSchemaInput : K extends "Person" ? PersonSchemaInput : K extends "VideoObject" ? VideoSchemaInput : K extends "BreadcrumbList" ? Array<{
|
|
13
|
+
name: string;
|
|
14
|
+
item: string;
|
|
15
|
+
position?: number;
|
|
16
|
+
}> : K extends "Course" ? CourseSchemaInput : never;
|
|
17
|
+
export declare const schemaFactory: {
|
|
18
|
+
generate<K extends SchemaKind>(kind: K, input: GeneratorInput<K>, options?: SchemaGeneratorOptions): JsonLdTypes;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { generateArticleSchema } from "./generators/article.js";
|
|
2
|
+
import { generateBreadcrumbSchema } from "./generators/breadcrumb.js";
|
|
3
|
+
import { generateFAQSchema } from "./generators/faq.js";
|
|
4
|
+
import { generateLocalBusinessSchema } from "./generators/local-business.js";
|
|
5
|
+
import { generateOrganizationSchema } from "./generators/organization.js";
|
|
6
|
+
import { generatePersonSchema } from "./generators/person.js";
|
|
7
|
+
import { generateProductSchema } from "./generators/product.js";
|
|
8
|
+
import { generateVideoSchema } from "./generators/video.js";
|
|
9
|
+
import { generateWebSiteSchema } from "./generators/website.js";
|
|
10
|
+
import { generateCourseSchema } from "./generators/course.js";
|
|
11
|
+
export const schemaFactory = {
|
|
12
|
+
generate(kind, input, options) {
|
|
13
|
+
switch (kind) {
|
|
14
|
+
case "Article":
|
|
15
|
+
case "NewsArticle":
|
|
16
|
+
case "BlogPosting":
|
|
17
|
+
return generateArticleSchema(input, options);
|
|
18
|
+
case "Product":
|
|
19
|
+
return generateProductSchema(input, options);
|
|
20
|
+
case "Course":
|
|
21
|
+
return generateCourseSchema(input, options);
|
|
22
|
+
case "Organization":
|
|
23
|
+
return generateOrganizationSchema(input, options);
|
|
24
|
+
case "LocalBusiness":
|
|
25
|
+
return generateLocalBusinessSchema(input, options);
|
|
26
|
+
case "BreadcrumbList":
|
|
27
|
+
return generateBreadcrumbSchema(input, options);
|
|
28
|
+
case "FAQPage":
|
|
29
|
+
return generateFAQSchema(input, options);
|
|
30
|
+
case "WebSite":
|
|
31
|
+
return generateWebSiteSchema(input, options);
|
|
32
|
+
case "Person":
|
|
33
|
+
return generatePersonSchema(input, options);
|
|
34
|
+
case "VideoObject":
|
|
35
|
+
return generateVideoSchema(input, options);
|
|
36
|
+
default: {
|
|
37
|
+
const _exhaustive = kind;
|
|
38
|
+
throw new Error(`[SEO] Unknown schema kind: ${String(_exhaustive)}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ArticleJsonLd, SchemaGeneratorOptions } from "../../../types/schema.js";
|
|
2
|
+
import type { ArticleSchemaInput } from "../types.js";
|
|
3
|
+
export declare const generateArticleSchema: (input: ArticleSchemaInput, options?: SchemaGeneratorOptions) => ArticleJsonLd;
|
|
4
|
+
export type { ArticleSchemaInput, SchemaGeneratorOptions };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createBuilder, withContext } from "../base.js";
|
|
2
|
+
export const generateArticleSchema = createBuilder((input, ctx) => {
|
|
3
|
+
ctx.required(input.headline, "headline");
|
|
4
|
+
ctx.required(input.image, "image");
|
|
5
|
+
ctx.required(input.datePublished, "datePublished");
|
|
6
|
+
ctx.required(input.authorName, "authorName");
|
|
7
|
+
ctx.required(input.publisherName, "publisherName");
|
|
8
|
+
ctx.required(input.publisherLogo, "publisherLogo");
|
|
9
|
+
ctx.set(withContext(input.type ?? "Article"));
|
|
10
|
+
ctx.set({
|
|
11
|
+
headline: input.headline,
|
|
12
|
+
name: input.headline,
|
|
13
|
+
description: input.description,
|
|
14
|
+
image: input.image,
|
|
15
|
+
datePublished: input.datePublished,
|
|
16
|
+
dateModified: input.dateModified,
|
|
17
|
+
author: {
|
|
18
|
+
"@type": input.authorType ?? "Person",
|
|
19
|
+
name: input.authorName,
|
|
20
|
+
url: input.authorUrl,
|
|
21
|
+
},
|
|
22
|
+
publisher: {
|
|
23
|
+
"@context": "https://schema.org",
|
|
24
|
+
"@type": "Organization",
|
|
25
|
+
name: input.publisherName,
|
|
26
|
+
logo: input.publisherLogo,
|
|
27
|
+
url: input.publisherUrl,
|
|
28
|
+
},
|
|
29
|
+
url: input.url,
|
|
30
|
+
articleSection: input.articleSection,
|
|
31
|
+
wordCount: input.wordCount,
|
|
32
|
+
keywords: Array.isArray(input.keywords) ? input.keywords.join(", ") : input.keywords,
|
|
33
|
+
inLanguage: input.inLanguage,
|
|
34
|
+
mainEntityOfPage: {
|
|
35
|
+
"@type": "WebPage",
|
|
36
|
+
"@id": input.url,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
});
|