@lexingtonthemes/seo 0.1.0 → 0.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/LICENSE +21 -0
- package/README.md +46 -9
- package/package.json +15 -10
- package/src/AstroSeo.astro +2 -0
- package/src/types.ts +2 -0
- package/src/utils/buildTags.ts +14 -0
- package/src/__test__/buildTags.test.ts +0 -441
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lexington Themes
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
SEO component for Astro projects.
|
|
4
4
|
|
|
5
|
-
This package renders SEO
|
|
5
|
+
This package renders SEO tags in your page `<head>` using a single `AstroSeo` component: **meta** and **link** tags (title, description, canonical), **Open Graph**, **Twitter Cards**, **Facebook** (`fb:app_id`), **robots** (noindex, nofollow, advanced directives), **language alternates** (hreflang), **mobile alternate**, and **JSON-LD** structured data.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -57,20 +57,20 @@ import { AstroSeo } from "@lexingtonthemes/seo";
|
|
|
57
57
|
---
|
|
58
58
|
|
|
59
59
|
<AstroSeo
|
|
60
|
-
title="Astro
|
|
61
|
-
description="Fast, modern
|
|
62
|
-
canonical="https://example.com/templates/
|
|
60
|
+
title="Premium Astro themes"
|
|
61
|
+
description="Fast, modern websites built with Astro."
|
|
62
|
+
canonical="https://example.com/templates/themes"
|
|
63
63
|
openGraph={{
|
|
64
|
-
url: "https://example.com/templates/
|
|
65
|
-
title: "Astro
|
|
66
|
-
description: "Fast, modern
|
|
64
|
+
url: "https://example.com/templates/themes",
|
|
65
|
+
title: "Astro themes",
|
|
66
|
+
description: "Fast, modern websites built with Astro.",
|
|
67
67
|
site_name: "Lexington Themes",
|
|
68
68
|
images: [
|
|
69
69
|
{
|
|
70
|
-
url: "https://example.com/og/
|
|
70
|
+
url: "https://example.com/og/themes.jpg",
|
|
71
71
|
width: 1200,
|
|
72
72
|
height: 630,
|
|
73
|
-
alt: "
|
|
73
|
+
alt: "themes Preview",
|
|
74
74
|
},
|
|
75
75
|
],
|
|
76
76
|
}}
|
|
@@ -136,6 +136,34 @@ import { AstroSeo } from "@lexingtonthemes/seo";
|
|
|
136
136
|
/>
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
+
### JSON-LD (structured data)
|
|
140
|
+
|
|
141
|
+
```astro
|
|
142
|
+
---
|
|
143
|
+
import { AstroSeo } from "@lexingtonthemes/seo";
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
<AstroSeo
|
|
147
|
+
title="Lexington Themes"
|
|
148
|
+
description="Production-ready Astro themes."
|
|
149
|
+
canonical="https://example.com/"
|
|
150
|
+
jsonLd={[
|
|
151
|
+
{
|
|
152
|
+
"@context": "https://schema.org",
|
|
153
|
+
"@type": "Organization",
|
|
154
|
+
name: "Lexington Themes",
|
|
155
|
+
url: "https://example.com",
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"@context": "https://schema.org",
|
|
159
|
+
"@type": "WebSite",
|
|
160
|
+
name: "Lexington Themes",
|
|
161
|
+
url: "https://example.com",
|
|
162
|
+
},
|
|
163
|
+
]}
|
|
164
|
+
/>
|
|
165
|
+
```
|
|
166
|
+
|
|
139
167
|
## Migrating from `@astrolib/seo`
|
|
140
168
|
|
|
141
169
|
If your existing themes already use `AstroSeo`, only the import path changes:
|
|
@@ -158,6 +186,7 @@ Main props include:
|
|
|
158
186
|
- `noindex`, `nofollow`, `robotsProps`
|
|
159
187
|
- `languageAlternates`, `mobileAlternate`
|
|
160
188
|
- `additionalMetaTags`, `additionalLinkTags`
|
|
189
|
+
- `jsonLd` – one or more JSON-LD schema objects (see below)
|
|
161
190
|
|
|
162
191
|
For full types, see `src/types.ts`.
|
|
163
192
|
|
|
@@ -217,9 +246,17 @@ For full types, see `src/types.ts`.
|
|
|
217
246
|
- Add custom HTML5 / RDFa / HTTP-Equiv meta tags via `additionalMetaTags`
|
|
218
247
|
- Add custom link tags (icon, manifest, preconnect, alternate, etc.) via `additionalLinkTags`
|
|
219
248
|
|
|
249
|
+
### JSON-LD
|
|
250
|
+
|
|
251
|
+
- Pass one or more [JSON-LD](https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data) schema objects via the `jsonLd` prop. Each object is rendered as a `<script type="application/ld+json">` tag. Use a single object or an array of objects for multiple schemas (e.g. Organization + WebSite). Values are stringified and safely escaped (e.g. `</script>` in strings) so the markup is valid.
|
|
252
|
+
|
|
220
253
|
## Development
|
|
221
254
|
|
|
222
255
|
```bash
|
|
223
256
|
npm install
|
|
224
257
|
npm test
|
|
225
258
|
```
|
|
259
|
+
|
|
260
|
+
## License
|
|
261
|
+
|
|
262
|
+
MIT © [Lexington Themes](https://lexingtonthemes.com)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexingtonthemes/seo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "SEO
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Astro SEO: meta, Open Graph, Twitter, JSON-LD, canonical, robots",
|
|
5
5
|
"homepage": "https://github.com/Lexington-Themes/lexington-seo",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/Lexington-Themes/lexington-seo/issues"
|
|
@@ -27,26 +27,31 @@
|
|
|
27
27
|
"./package.json": "./package.json"
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"index.ts",
|
|
31
|
+
"src/AstroSeo.astro",
|
|
32
|
+
"src/types.ts",
|
|
33
|
+
"src/utils"
|
|
32
34
|
],
|
|
33
35
|
"keywords": [
|
|
34
|
-
"astro-component",
|
|
35
|
-
"withastro",
|
|
36
|
-
"astro",
|
|
37
|
-
"lexington",
|
|
38
36
|
"seo",
|
|
37
|
+
"astro",
|
|
39
38
|
"astro-seo",
|
|
39
|
+
"lexington",
|
|
40
|
+
"withastro",
|
|
41
|
+
"astro-component",
|
|
40
42
|
"astro-integration"
|
|
41
43
|
],
|
|
42
44
|
"scripts": {
|
|
43
|
-
"test": "jest"
|
|
45
|
+
"test": "jest",
|
|
46
|
+
"prepublishOnly": "npm test"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"html-escaper": "^3.0.3"
|
|
44
50
|
},
|
|
45
51
|
"devDependencies": {
|
|
46
52
|
"@types/html-escaper": "^3.0.0",
|
|
47
53
|
"@types/jest": "^29.5.4",
|
|
48
54
|
"astro": "^1.2.1 || ^2.0.0 || ^3.0.0-beta.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0",
|
|
49
|
-
"html-escaper": "^3.0.3",
|
|
50
55
|
"html-validate": "^8.18.2",
|
|
51
56
|
"jest": "^29.6.3",
|
|
52
57
|
"ts-jest": "^29.1.1",
|
package/src/AstroSeo.astro
CHANGED
package/src/types.ts
CHANGED
|
@@ -452,4 +452,6 @@ export interface AstroSeoProps {
|
|
|
452
452
|
twitter?: Twitter;
|
|
453
453
|
additionalMetaTags?: ReadonlyArray<MetaTag>;
|
|
454
454
|
additionalLinkTags?: ReadonlyArray<LinkTag>;
|
|
455
|
+
/** One or more JSON-LD schema objects to render as script tags. */
|
|
456
|
+
jsonLd?: Record<string, unknown> | ReadonlyArray<Record<string, unknown>>;
|
|
455
457
|
}
|
package/src/utils/buildTags.ts
CHANGED
|
@@ -453,5 +453,19 @@ export const buildTags = (config: AstroSeoProps): string => {
|
|
|
453
453
|
});
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
// JSON-LD
|
|
457
|
+
if (config.jsonLd) {
|
|
458
|
+
const schemas = Array.isArray(config.jsonLd)
|
|
459
|
+
? config.jsonLd
|
|
460
|
+
: [config.jsonLd];
|
|
461
|
+
for (const schema of schemas) {
|
|
462
|
+
if (schema && typeof schema === "object") {
|
|
463
|
+
let json = JSON.stringify(schema);
|
|
464
|
+
json = json.replace(/<\/script/gi, "<\\/script");
|
|
465
|
+
addTag(`<script type="application/ld+json">${json}</script>`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
456
470
|
return tagsToRender.trim();
|
|
457
471
|
};
|
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
import { buildTags } from "../utils/buildTags";
|
|
2
|
-
import { HtmlValidate as _HtmlValidate } from "html-validate/node";
|
|
3
|
-
|
|
4
|
-
const validate = new _HtmlValidate();
|
|
5
|
-
|
|
6
|
-
describe("buildTags function", () => {
|
|
7
|
-
it("should return an empty string if no config is provided", () => {
|
|
8
|
-
const result = buildTags({});
|
|
9
|
-
expect(result).toBe("");
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("should handle null or undefined values gracefully", () => {
|
|
13
|
-
const config = {
|
|
14
|
-
title: null,
|
|
15
|
-
description: undefined,
|
|
16
|
-
};
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
const result = buildTags(config);
|
|
19
|
-
expect(result).not.toContain("null");
|
|
20
|
-
expect(result).not.toContain("undefined");
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("should escape special characters correctly", async () => {
|
|
24
|
-
const config = {
|
|
25
|
-
title: "Title & Description",
|
|
26
|
-
};
|
|
27
|
-
const result = buildTags(config);
|
|
28
|
-
expect(result).toContain("Title & Description");
|
|
29
|
-
|
|
30
|
-
const htmlResult = await validate.validateString(result);
|
|
31
|
-
expect(htmlResult.valid).toBe(true);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should generate correct title tag", async () => {
|
|
35
|
-
const config = {
|
|
36
|
-
title: '<script>alert("hacked")</script>',
|
|
37
|
-
};
|
|
38
|
-
const result = buildTags(config);
|
|
39
|
-
expect(result).toContain(
|
|
40
|
-
"<title><script>alert("hacked")</script></title>"
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const htmlResult = await validate.validateString(result);
|
|
44
|
-
expect(htmlResult.valid).toBe(true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should generate correct description tag", async () => {
|
|
48
|
-
const config = {
|
|
49
|
-
description: '<img src=x onerror=alert("hacked")>',
|
|
50
|
-
};
|
|
51
|
-
const result = buildTags(config);
|
|
52
|
-
expect(result).toContain(
|
|
53
|
-
'<meta name="description" content="<img src=x onerror=alert("hacked")>">'
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const htmlResult = await validate.validateString(result);
|
|
57
|
-
expect(htmlResult.valid).toBe(true);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("should escape URLs", async () => {
|
|
61
|
-
const config = {
|
|
62
|
-
openGraph: {
|
|
63
|
-
url: '<script>alert("hacked")</script>',
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
const result = buildTags(config);
|
|
67
|
-
expect(result).toContain(
|
|
68
|
-
'<meta property="og:url" content="<script>alert("hacked")</script>">'
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const htmlResult = await validate.validateString(result);
|
|
72
|
-
expect(htmlResult.valid).toBe(true);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("should generate correct robots tag for noindex and nofollow", async () => {
|
|
76
|
-
const config = {
|
|
77
|
-
noindex: true,
|
|
78
|
-
nofollow: true,
|
|
79
|
-
};
|
|
80
|
-
const result = buildTags(config);
|
|
81
|
-
expect(result).toContain('<meta name="robots" content="noindex,nofollow">');
|
|
82
|
-
|
|
83
|
-
const htmlResult = await validate.validateString(result);
|
|
84
|
-
expect(htmlResult.valid).toBe(true);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("should generate correct twitter card tag", async () => {
|
|
88
|
-
const config = {
|
|
89
|
-
twitter: {
|
|
90
|
-
cardType: "summary_large_image",
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
const result = buildTags(config);
|
|
94
|
-
expect(result).toContain(
|
|
95
|
-
'<meta name="twitter:card" content="summary_large_image">'
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const htmlResult = await validate.validateString(result);
|
|
99
|
-
expect(htmlResult.valid).toBe(true);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("should generate correct facebook app id tag", async () => {
|
|
103
|
-
const config = {
|
|
104
|
-
facebook: {
|
|
105
|
-
appId: "1234567890",
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
const result = buildTags(config);
|
|
109
|
-
expect(result).toContain(
|
|
110
|
-
'<meta property="fb:app_id" content="1234567890">'
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const htmlResult = await validate.validateString(result);
|
|
114
|
-
expect(htmlResult.valid).toBe(true);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("should generate correct openGraph title tag", async () => {
|
|
118
|
-
const config = {
|
|
119
|
-
openGraph: {
|
|
120
|
-
title: "<b>Test Title</b>",
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
const result = buildTags(config);
|
|
124
|
-
expect(result).toContain(
|
|
125
|
-
'<meta property="og:title" content="<b>Test Title</b>">'
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
const htmlResult = await validate.validateString(result);
|
|
129
|
-
expect(htmlResult.valid).toBe(true);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("should generate correct canonical link tag", async () => {
|
|
133
|
-
const config = {
|
|
134
|
-
canonical: "https://example.com/page",
|
|
135
|
-
};
|
|
136
|
-
const result = buildTags(config);
|
|
137
|
-
expect(result).toContain(
|
|
138
|
-
'<link rel="canonical" href="https://example.com/page">'
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const htmlResult = await validate.validateString(result);
|
|
142
|
-
expect(htmlResult.valid).toBe(true);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("should generate correct alternate link tag for mobile", async () => {
|
|
146
|
-
const config = {
|
|
147
|
-
mobileAlternate: {
|
|
148
|
-
media: "only screen and (max-width: 640px)",
|
|
149
|
-
href: "https://m.example.com/page",
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
const result = buildTags(config);
|
|
153
|
-
expect(result).toContain(
|
|
154
|
-
'<link rel="alternate" media="only screen and (max-width: 640px)" href="https://m.example.com/page">'
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
const htmlResult = await validate.validateString(result);
|
|
158
|
-
expect(htmlResult.valid).toBe(true);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("should generate correct openGraph description tag", async () => {
|
|
162
|
-
const config = {
|
|
163
|
-
openGraph: {
|
|
164
|
-
description: "<i>Test Description</i>",
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
const result = buildTags(config);
|
|
168
|
-
expect(result).toContain(
|
|
169
|
-
'<meta property="og:description" content="<i>Test Description</i>">'
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
const htmlResult = await validate.validateString(result);
|
|
173
|
-
expect(htmlResult.valid).toBe(true);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("should generate correct openGraph type tag", async () => {
|
|
177
|
-
const config = {
|
|
178
|
-
openGraph: {
|
|
179
|
-
type: "article",
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
const result = buildTags(config);
|
|
183
|
-
expect(result).toContain('<meta property="og:type" content="article">');
|
|
184
|
-
|
|
185
|
-
const htmlResult = await validate.validateString(result);
|
|
186
|
-
expect(htmlResult.valid).toBe(true);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("should generate correct openGraph locale tag", async () => {
|
|
190
|
-
const config = {
|
|
191
|
-
openGraph: {
|
|
192
|
-
locale: "en_US",
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
const result = buildTags(config);
|
|
196
|
-
expect(result).toContain('<meta property="og:locale" content="en_US">');
|
|
197
|
-
|
|
198
|
-
const htmlResult = await validate.validateString(result);
|
|
199
|
-
expect(htmlResult.valid).toBe(true);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it("should generate correct openGraph site_name tag", async () => {
|
|
203
|
-
const config = {
|
|
204
|
-
openGraph: {
|
|
205
|
-
site_name: "Test Site",
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
|
-
const result = buildTags(config);
|
|
209
|
-
expect(result).toContain(
|
|
210
|
-
'<meta property="og:site_name" content="Test Site">'
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
const htmlResult = await validate.validateString(result);
|
|
214
|
-
expect(htmlResult.valid).toBe(true);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("should handle multiple OpenGraph media tags correctly", async () => {
|
|
218
|
-
const config = {
|
|
219
|
-
openGraph: {
|
|
220
|
-
images: [
|
|
221
|
-
{ url: "https://example.com/image1.jpg" },
|
|
222
|
-
{ url: "https://example.com/image2.jpg" },
|
|
223
|
-
],
|
|
224
|
-
videos: [
|
|
225
|
-
{ url: "https://example.com/video1.mp4" },
|
|
226
|
-
{ url: "https://example.com/video2.mp4" },
|
|
227
|
-
],
|
|
228
|
-
},
|
|
229
|
-
};
|
|
230
|
-
const result = buildTags(config);
|
|
231
|
-
expect(result).toContain(
|
|
232
|
-
'<meta property="og:image" content="https://example.com/image1.jpg">'
|
|
233
|
-
);
|
|
234
|
-
expect(result).toContain(
|
|
235
|
-
'<meta property="og:image" content="https://example.com/image2.jpg">'
|
|
236
|
-
);
|
|
237
|
-
expect(result).toContain(
|
|
238
|
-
'<meta property="og:video" content="https://example.com/video1.mp4">'
|
|
239
|
-
);
|
|
240
|
-
expect(result).toContain(
|
|
241
|
-
'<meta property="og:video" content="https://example.com/video2.mp4">'
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
const htmlResult = await validate.validateString(result);
|
|
245
|
-
expect(htmlResult.valid).toBe(true);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it("should generate correct languageAlternates link tags", async () => {
|
|
249
|
-
const config = {
|
|
250
|
-
languageAlternates: [
|
|
251
|
-
{ hreflang: "es", href: "https://example.com/es" },
|
|
252
|
-
{ hreflang: "fr", href: "https://example.com/fr" },
|
|
253
|
-
],
|
|
254
|
-
};
|
|
255
|
-
const result = buildTags(config);
|
|
256
|
-
expect(result).toContain(
|
|
257
|
-
'<link rel="alternate" hreflang="es" href="https://example.com/es">'
|
|
258
|
-
);
|
|
259
|
-
expect(result).toContain(
|
|
260
|
-
'<link rel="alternate" hreflang="fr" href="https://example.com/fr">'
|
|
261
|
-
);
|
|
262
|
-
|
|
263
|
-
const htmlResult = await validate.validateString(result);
|
|
264
|
-
expect(htmlResult.valid).toBe(true);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it("should generate correct twitter site and creator tags", async () => {
|
|
268
|
-
const config = {
|
|
269
|
-
twitter: {
|
|
270
|
-
site: "@testsite",
|
|
271
|
-
handle: "@testhandle",
|
|
272
|
-
},
|
|
273
|
-
};
|
|
274
|
-
const result = buildTags(config);
|
|
275
|
-
expect(result).toContain('<meta name="twitter:site" content="@testsite">');
|
|
276
|
-
expect(result).toContain(
|
|
277
|
-
'<meta name="twitter:creator" content="@testhandle">'
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
const htmlResult = await validate.validateString(result);
|
|
281
|
-
expect(htmlResult.valid).toBe(true);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
it("should generate correct additionalMetaTags", async () => {
|
|
285
|
-
const config = {
|
|
286
|
-
additionalMetaTags: [
|
|
287
|
-
{ name: "viewport", content: "width=device-width, initial-scale=1" },
|
|
288
|
-
],
|
|
289
|
-
};
|
|
290
|
-
const result = buildTags(config);
|
|
291
|
-
expect(result).toContain(
|
|
292
|
-
'<meta content="width=device-width, initial-scale=1" name="viewport">'
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
const htmlResult = await validate.validateString(result);
|
|
296
|
-
expect(htmlResult.valid).toBe(true);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it("should generate correct additionalLinkTags", async () => {
|
|
300
|
-
const config = {
|
|
301
|
-
additionalLinkTags: [
|
|
302
|
-
{ rel: "stylesheet", href: "https://example.com/styles.css" },
|
|
303
|
-
],
|
|
304
|
-
};
|
|
305
|
-
const result = buildTags(config);
|
|
306
|
-
expect(result).toContain(
|
|
307
|
-
'<link rel="stylesheet" href="https://example.com/styles.css">'
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
const htmlResult = await validate.validateString(result);
|
|
311
|
-
expect(htmlResult.valid).toBe(true);
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
it("should generate og:title and og:description from title and description if not explicitly set", async () => {
|
|
315
|
-
const config = {
|
|
316
|
-
title: "Test Title",
|
|
317
|
-
description: "Test Description",
|
|
318
|
-
openGraph: {},
|
|
319
|
-
};
|
|
320
|
-
const result = buildTags(config);
|
|
321
|
-
expect(result).toContain('<meta property="og:title" content="Test Title">');
|
|
322
|
-
expect(result).toContain(
|
|
323
|
-
'<meta property="og:description" content="Test Description">'
|
|
324
|
-
);
|
|
325
|
-
|
|
326
|
-
const htmlResult = await validate.validateString(result);
|
|
327
|
-
expect(htmlResult.valid).toBe(true);
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
it("should not generate og:title and og:description if openGraph is not defined", async () => {
|
|
331
|
-
const config = {
|
|
332
|
-
title: "Test Title",
|
|
333
|
-
description: "Test Description",
|
|
334
|
-
};
|
|
335
|
-
const result = buildTags(config);
|
|
336
|
-
expect(result).not.toContain(
|
|
337
|
-
'<meta property="og:title" content="Test Title">'
|
|
338
|
-
);
|
|
339
|
-
expect(result).not.toContain(
|
|
340
|
-
'<meta property="og:description" content="Test Description">'
|
|
341
|
-
);
|
|
342
|
-
|
|
343
|
-
const htmlResult = await validate.validateString(result);
|
|
344
|
-
expect(htmlResult.valid).toBe(true);
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
// Casos de prueba realistas
|
|
348
|
-
it("should generate a complete set of tags for a blog post", async () => {
|
|
349
|
-
const config = {
|
|
350
|
-
title: "My Blog Post",
|
|
351
|
-
description: "A detailed description of my blog post.",
|
|
352
|
-
canonical: "https://example.com/blog/my-blog-post",
|
|
353
|
-
openGraph: {
|
|
354
|
-
type: "article",
|
|
355
|
-
url: "https://example.com/blog/my-blog-post",
|
|
356
|
-
title: "My Blog Post",
|
|
357
|
-
description: "A detailed description of my blog post.",
|
|
358
|
-
images: [{ url: "https://example.com/images/blog-image.jpg" }],
|
|
359
|
-
},
|
|
360
|
-
twitter: {
|
|
361
|
-
cardType: "summary_large_image",
|
|
362
|
-
site: "@example",
|
|
363
|
-
},
|
|
364
|
-
};
|
|
365
|
-
const result = buildTags(config);
|
|
366
|
-
expect(result).toContain("<title>My Blog Post</title>");
|
|
367
|
-
expect(result).toContain(
|
|
368
|
-
'<meta name="description" content="A detailed description of my blog post.">'
|
|
369
|
-
);
|
|
370
|
-
expect(result).toContain(
|
|
371
|
-
'<link rel="canonical" href="https://example.com/blog/my-blog-post">'
|
|
372
|
-
);
|
|
373
|
-
expect(result).toContain('<meta property="og:type" content="article">');
|
|
374
|
-
expect(result).toContain(
|
|
375
|
-
'<meta property="og:url" content="https://example.com/blog/my-blog-post">'
|
|
376
|
-
);
|
|
377
|
-
expect(result).toContain(
|
|
378
|
-
'<meta property="og:title" content="My Blog Post">'
|
|
379
|
-
);
|
|
380
|
-
expect(result).toContain(
|
|
381
|
-
'<meta property="og:description" content="A detailed description of my blog post.">'
|
|
382
|
-
);
|
|
383
|
-
expect(result).toContain(
|
|
384
|
-
'<meta property="og:image" content="https://example.com/images/blog-image.jpg">'
|
|
385
|
-
);
|
|
386
|
-
expect(result).toContain(
|
|
387
|
-
'<meta name="twitter:card" content="summary_large_image">'
|
|
388
|
-
);
|
|
389
|
-
expect(result).toContain('<meta name="twitter:site" content="@example">');
|
|
390
|
-
|
|
391
|
-
const htmlResult = await validate.validateString(result);
|
|
392
|
-
expect(htmlResult.valid).toBe(true);
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it("should generate a complete set of tags for a product page", async () => {
|
|
396
|
-
const config = {
|
|
397
|
-
title: "Product Name",
|
|
398
|
-
description: "Description of the product.",
|
|
399
|
-
canonical: "https://example.com/products/product-name",
|
|
400
|
-
openGraph: {
|
|
401
|
-
type: "product",
|
|
402
|
-
url: "https://example.com/products/product-name",
|
|
403
|
-
title: "Product Name",
|
|
404
|
-
description: "Description of the product.",
|
|
405
|
-
images: [{ url: "https://example.com/images/product-image.jpg" }],
|
|
406
|
-
},
|
|
407
|
-
twitter: {
|
|
408
|
-
cardType: "summary",
|
|
409
|
-
site: "@examplestore",
|
|
410
|
-
},
|
|
411
|
-
};
|
|
412
|
-
const result = buildTags(config);
|
|
413
|
-
expect(result).toContain("<title>Product Name</title>");
|
|
414
|
-
expect(result).toContain(
|
|
415
|
-
'<meta name="description" content="Description of the product.">'
|
|
416
|
-
);
|
|
417
|
-
expect(result).toContain(
|
|
418
|
-
'<link rel="canonical" href="https://example.com/products/product-name">'
|
|
419
|
-
);
|
|
420
|
-
expect(result).toContain('<meta property="og:type" content="product">');
|
|
421
|
-
expect(result).toContain(
|
|
422
|
-
'<meta property="og:url" content="https://example.com/products/product-name">'
|
|
423
|
-
);
|
|
424
|
-
expect(result).toContain(
|
|
425
|
-
'<meta property="og:title" content="Product Name">'
|
|
426
|
-
);
|
|
427
|
-
expect(result).toContain(
|
|
428
|
-
'<meta property="og:description" content="Description of the product.">'
|
|
429
|
-
);
|
|
430
|
-
expect(result).toContain(
|
|
431
|
-
'<meta property="og:image" content="https://example.com/images/product-image.jpg">'
|
|
432
|
-
);
|
|
433
|
-
expect(result).toContain('<meta name="twitter:card" content="summary">');
|
|
434
|
-
expect(result).toContain(
|
|
435
|
-
'<meta name="twitter:site" content="@examplestore">'
|
|
436
|
-
);
|
|
437
|
-
|
|
438
|
-
const htmlResult = await validate.validateString(result);
|
|
439
|
-
expect(htmlResult.valid).toBe(true);
|
|
440
|
-
});
|
|
441
|
-
});
|