@coherent.js/seo 1.0.0-beta.2
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/dist/index.js +549 -0
- package/package.json +42 -0
- package/types/index.d.ts +192 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Thomas Drouvin
|
|
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/dist/index.js
ADDED
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
// src/meta.js
|
|
2
|
+
var MetaBuilder = class {
|
|
3
|
+
constructor(defaults = {}) {
|
|
4
|
+
this.defaults = {
|
|
5
|
+
siteName: "",
|
|
6
|
+
siteUrl: "",
|
|
7
|
+
locale: "en_US",
|
|
8
|
+
twitterHandle: "",
|
|
9
|
+
...defaults
|
|
10
|
+
};
|
|
11
|
+
this.tags = [];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Set page title
|
|
15
|
+
*/
|
|
16
|
+
title(title, options = {}) {
|
|
17
|
+
const fullTitle = options.template ? options.template.replace("%s", title) : title;
|
|
18
|
+
this.tags.push({ title: { text: fullTitle } });
|
|
19
|
+
this.og("title", fullTitle);
|
|
20
|
+
this.twitter("title", fullTitle);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Set page description
|
|
25
|
+
*/
|
|
26
|
+
description(description) {
|
|
27
|
+
this.tags.push({
|
|
28
|
+
meta: {
|
|
29
|
+
name: "description",
|
|
30
|
+
content: description
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this.og("description", description);
|
|
34
|
+
this.twitter("description", description);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set canonical URL
|
|
39
|
+
*/
|
|
40
|
+
canonical(url) {
|
|
41
|
+
this.tags.push({
|
|
42
|
+
link: {
|
|
43
|
+
rel: "canonical",
|
|
44
|
+
href: url
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
this.og("url", url);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Set keywords
|
|
52
|
+
*/
|
|
53
|
+
keywords(keywords) {
|
|
54
|
+
const keywordString = Array.isArray(keywords) ? keywords.join(", ") : keywords;
|
|
55
|
+
this.tags.push({
|
|
56
|
+
meta: {
|
|
57
|
+
name: "keywords",
|
|
58
|
+
content: keywordString
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Set robots directives
|
|
65
|
+
*/
|
|
66
|
+
robots(directives) {
|
|
67
|
+
const content = Array.isArray(directives) ? directives.join(", ") : directives;
|
|
68
|
+
this.tags.push({
|
|
69
|
+
meta: {
|
|
70
|
+
name: "robots",
|
|
71
|
+
content
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Set Open Graph tag
|
|
78
|
+
*/
|
|
79
|
+
og(property, content) {
|
|
80
|
+
this.tags.push({
|
|
81
|
+
meta: {
|
|
82
|
+
property: `og:${property}`,
|
|
83
|
+
content
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Set Twitter Card tag
|
|
90
|
+
*/
|
|
91
|
+
twitter(name, content) {
|
|
92
|
+
this.tags.push({
|
|
93
|
+
meta: {
|
|
94
|
+
name: `twitter:${name}`,
|
|
95
|
+
content
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Set image for social sharing
|
|
102
|
+
*/
|
|
103
|
+
image(url, options = {}) {
|
|
104
|
+
this.og("image", url);
|
|
105
|
+
if (options.width) this.og("image:width", options.width);
|
|
106
|
+
if (options.height) this.og("image:height", options.height);
|
|
107
|
+
if (options.alt) this.og("image:alt", options.alt);
|
|
108
|
+
this.twitter("image", url);
|
|
109
|
+
if (options.alt) this.twitter("image:alt", options.alt);
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Set article metadata
|
|
114
|
+
*/
|
|
115
|
+
article(options = {}) {
|
|
116
|
+
this.og("type", "article");
|
|
117
|
+
if (options.publishedTime) {
|
|
118
|
+
this.og("article:published_time", options.publishedTime);
|
|
119
|
+
}
|
|
120
|
+
if (options.modifiedTime) {
|
|
121
|
+
this.og("article:modified_time", options.modifiedTime);
|
|
122
|
+
}
|
|
123
|
+
if (options.author) {
|
|
124
|
+
this.og("article:author", options.author);
|
|
125
|
+
}
|
|
126
|
+
if (options.section) {
|
|
127
|
+
this.og("article:section", options.section);
|
|
128
|
+
}
|
|
129
|
+
if (options.tags) {
|
|
130
|
+
options.tags.forEach((tag) => this.og("article:tag", tag));
|
|
131
|
+
}
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Set Twitter Card type
|
|
136
|
+
*/
|
|
137
|
+
twitterCard(type = "summary_large_image") {
|
|
138
|
+
this.twitter("card", type);
|
|
139
|
+
if (this.defaults.twitterHandle) {
|
|
140
|
+
this.twitter("site", this.defaults.twitterHandle);
|
|
141
|
+
}
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Set locale
|
|
146
|
+
*/
|
|
147
|
+
locale(locale, alternates = []) {
|
|
148
|
+
this.og("locale", locale);
|
|
149
|
+
alternates.forEach((alt) => {
|
|
150
|
+
this.og("locale:alternate", alt);
|
|
151
|
+
});
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Set site name
|
|
156
|
+
*/
|
|
157
|
+
siteName(name) {
|
|
158
|
+
this.og("site_name", name || this.defaults.siteName);
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Add custom meta tag
|
|
163
|
+
*/
|
|
164
|
+
meta(attributes) {
|
|
165
|
+
this.tags.push({ meta: attributes });
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Add link tag
|
|
170
|
+
*/
|
|
171
|
+
link(attributes) {
|
|
172
|
+
this.tags.push({ link: attributes });
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Build all meta tags
|
|
177
|
+
*/
|
|
178
|
+
build() {
|
|
179
|
+
return this.tags;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Reset builder
|
|
183
|
+
*/
|
|
184
|
+
reset() {
|
|
185
|
+
this.tags = [];
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
function createMetaBuilder(defaults = {}) {
|
|
190
|
+
return new MetaBuilder(defaults);
|
|
191
|
+
}
|
|
192
|
+
function generateMeta(options = {}) {
|
|
193
|
+
const builder = new MetaBuilder(options.defaults);
|
|
194
|
+
if (options.title) {
|
|
195
|
+
builder.title(options.title, { template: options.titleTemplate });
|
|
196
|
+
}
|
|
197
|
+
if (options.description) {
|
|
198
|
+
builder.description(options.description);
|
|
199
|
+
}
|
|
200
|
+
if (options.canonical) {
|
|
201
|
+
builder.canonical(options.canonical);
|
|
202
|
+
}
|
|
203
|
+
if (options.keywords) {
|
|
204
|
+
builder.keywords(options.keywords);
|
|
205
|
+
}
|
|
206
|
+
if (options.image) {
|
|
207
|
+
builder.image(options.image.url, options.image);
|
|
208
|
+
}
|
|
209
|
+
if (options.robots) {
|
|
210
|
+
builder.robots(options.robots);
|
|
211
|
+
}
|
|
212
|
+
if (options.article) {
|
|
213
|
+
builder.article(options.article);
|
|
214
|
+
}
|
|
215
|
+
if (options.twitterCard !== false) {
|
|
216
|
+
builder.twitterCard(options.twitterCard);
|
|
217
|
+
}
|
|
218
|
+
if (options.locale) {
|
|
219
|
+
builder.locale(options.locale, options.alternateLocales);
|
|
220
|
+
}
|
|
221
|
+
if (options.siteName) {
|
|
222
|
+
builder.siteName(options.siteName);
|
|
223
|
+
}
|
|
224
|
+
return builder.build();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/sitemap.js
|
|
228
|
+
var SitemapGenerator = class {
|
|
229
|
+
constructor(options = {}) {
|
|
230
|
+
this.options = {
|
|
231
|
+
hostname: "",
|
|
232
|
+
xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9",
|
|
233
|
+
...options
|
|
234
|
+
};
|
|
235
|
+
this.urls = [];
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Add URL to sitemap
|
|
239
|
+
*/
|
|
240
|
+
add(url, options = {}) {
|
|
241
|
+
this.urls.push({
|
|
242
|
+
loc: this.normalizeUrl(url),
|
|
243
|
+
lastmod: options.lastmod || (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
244
|
+
changefreq: options.changefreq || "weekly",
|
|
245
|
+
priority: options.priority !== void 0 ? options.priority : 0.5,
|
|
246
|
+
...options
|
|
247
|
+
});
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Add multiple URLs
|
|
252
|
+
*/
|
|
253
|
+
addMultiple(urls) {
|
|
254
|
+
urls.forEach((url) => {
|
|
255
|
+
if (typeof url === "string") {
|
|
256
|
+
this.add(url);
|
|
257
|
+
} else {
|
|
258
|
+
this.add(url.url, url);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Normalize URL
|
|
265
|
+
*/
|
|
266
|
+
normalizeUrl(url) {
|
|
267
|
+
if (url.startsWith("http")) {
|
|
268
|
+
return url;
|
|
269
|
+
}
|
|
270
|
+
const hostname = this.options.hostname.replace(/\/$/, "");
|
|
271
|
+
const path = url.startsWith("/") ? url : `/${url}`;
|
|
272
|
+
return `${hostname}${path}`;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Generate XML sitemap
|
|
276
|
+
*/
|
|
277
|
+
generate() {
|
|
278
|
+
const urlEntries = this.urls.map((url) => {
|
|
279
|
+
const entries = [` <loc>${this.escapeXml(url.loc)}</loc>`];
|
|
280
|
+
if (url.lastmod) {
|
|
281
|
+
entries.push(` <lastmod>${url.lastmod}</lastmod>`);
|
|
282
|
+
}
|
|
283
|
+
if (url.changefreq) {
|
|
284
|
+
entries.push(` <changefreq>${url.changefreq}</changefreq>`);
|
|
285
|
+
}
|
|
286
|
+
if (url.priority !== void 0) {
|
|
287
|
+
entries.push(` <priority>${url.priority}</priority>`);
|
|
288
|
+
}
|
|
289
|
+
return ` <url>
|
|
290
|
+
${entries.join("\n")}
|
|
291
|
+
</url>`;
|
|
292
|
+
}).join("\n");
|
|
293
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
294
|
+
<urlset xmlns="${this.options.xmlns}">
|
|
295
|
+
${urlEntries}
|
|
296
|
+
</urlset>`;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Escape XML special characters
|
|
300
|
+
*/
|
|
301
|
+
escapeXml(str) {
|
|
302
|
+
return String(str).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Clear all URLs
|
|
306
|
+
*/
|
|
307
|
+
clear() {
|
|
308
|
+
this.urls = [];
|
|
309
|
+
return this;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Get URL count
|
|
313
|
+
*/
|
|
314
|
+
count() {
|
|
315
|
+
return this.urls.length;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
function createSitemapGenerator(options = {}) {
|
|
319
|
+
return new SitemapGenerator(options);
|
|
320
|
+
}
|
|
321
|
+
function generateSitemap(urls, options = {}) {
|
|
322
|
+
const generator = new SitemapGenerator(options);
|
|
323
|
+
generator.addMultiple(urls);
|
|
324
|
+
return generator.generate();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// src/structured-data.js
|
|
328
|
+
var StructuredDataBuilder = class {
|
|
329
|
+
constructor() {
|
|
330
|
+
this.schemas = [];
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Add schema
|
|
334
|
+
*/
|
|
335
|
+
add(schema) {
|
|
336
|
+
this.schemas.push(schema);
|
|
337
|
+
return this;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Create Organization schema
|
|
341
|
+
*/
|
|
342
|
+
organization(data) {
|
|
343
|
+
return this.add({
|
|
344
|
+
"@context": "https://schema.org",
|
|
345
|
+
"@type": "Organization",
|
|
346
|
+
name: data.name,
|
|
347
|
+
url: data.url,
|
|
348
|
+
logo: data.logo,
|
|
349
|
+
description: data.description,
|
|
350
|
+
contactPoint: data.contactPoint,
|
|
351
|
+
sameAs: data.socialLinks
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Create WebSite schema
|
|
356
|
+
*/
|
|
357
|
+
website(data) {
|
|
358
|
+
return this.add({
|
|
359
|
+
"@context": "https://schema.org",
|
|
360
|
+
"@type": "WebSite",
|
|
361
|
+
name: data.name,
|
|
362
|
+
url: data.url,
|
|
363
|
+
description: data.description,
|
|
364
|
+
potentialAction: data.searchAction ? {
|
|
365
|
+
"@type": "SearchAction",
|
|
366
|
+
target: data.searchAction.target,
|
|
367
|
+
"query-input": data.searchAction.queryInput || "required name=search_term_string"
|
|
368
|
+
} : void 0
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Create Article schema
|
|
373
|
+
*/
|
|
374
|
+
article(data) {
|
|
375
|
+
return this.add({
|
|
376
|
+
"@context": "https://schema.org",
|
|
377
|
+
"@type": "Article",
|
|
378
|
+
headline: data.headline,
|
|
379
|
+
description: data.description,
|
|
380
|
+
image: data.image,
|
|
381
|
+
author: data.author ? {
|
|
382
|
+
"@type": "Person",
|
|
383
|
+
name: data.author.name,
|
|
384
|
+
url: data.author.url
|
|
385
|
+
} : void 0,
|
|
386
|
+
publisher: data.publisher ? {
|
|
387
|
+
"@type": "Organization",
|
|
388
|
+
name: data.publisher.name,
|
|
389
|
+
logo: data.publisher.logo ? {
|
|
390
|
+
"@type": "ImageObject",
|
|
391
|
+
url: data.publisher.logo
|
|
392
|
+
} : void 0
|
|
393
|
+
} : void 0,
|
|
394
|
+
datePublished: data.datePublished,
|
|
395
|
+
dateModified: data.dateModified
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Create Product schema
|
|
400
|
+
*/
|
|
401
|
+
product(data) {
|
|
402
|
+
return this.add({
|
|
403
|
+
"@context": "https://schema.org",
|
|
404
|
+
"@type": "Product",
|
|
405
|
+
name: data.name,
|
|
406
|
+
description: data.description,
|
|
407
|
+
image: data.image,
|
|
408
|
+
brand: data.brand ? {
|
|
409
|
+
"@type": "Brand",
|
|
410
|
+
name: data.brand
|
|
411
|
+
} : void 0,
|
|
412
|
+
offers: data.offers ? {
|
|
413
|
+
"@type": "Offer",
|
|
414
|
+
price: data.offers.price,
|
|
415
|
+
priceCurrency: data.offers.currency || "USD",
|
|
416
|
+
availability: data.offers.availability || "https://schema.org/InStock",
|
|
417
|
+
url: data.offers.url
|
|
418
|
+
} : void 0,
|
|
419
|
+
aggregateRating: data.rating ? {
|
|
420
|
+
"@type": "AggregateRating",
|
|
421
|
+
ratingValue: data.rating.value,
|
|
422
|
+
reviewCount: data.rating.count
|
|
423
|
+
} : void 0
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Create BreadcrumbList schema
|
|
428
|
+
*/
|
|
429
|
+
breadcrumb(items) {
|
|
430
|
+
return this.add({
|
|
431
|
+
"@context": "https://schema.org",
|
|
432
|
+
"@type": "BreadcrumbList",
|
|
433
|
+
itemListElement: items.map((item, index) => ({
|
|
434
|
+
"@type": "ListItem",
|
|
435
|
+
position: index + 1,
|
|
436
|
+
name: item.name,
|
|
437
|
+
item: item.url
|
|
438
|
+
}))
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Create FAQ schema
|
|
443
|
+
*/
|
|
444
|
+
faq(questions) {
|
|
445
|
+
return this.add({
|
|
446
|
+
"@context": "https://schema.org",
|
|
447
|
+
"@type": "FAQPage",
|
|
448
|
+
mainEntity: questions.map((q) => ({
|
|
449
|
+
"@type": "Question",
|
|
450
|
+
name: q.question,
|
|
451
|
+
acceptedAnswer: {
|
|
452
|
+
"@type": "Answer",
|
|
453
|
+
text: q.answer
|
|
454
|
+
}
|
|
455
|
+
}))
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Create Person schema
|
|
460
|
+
*/
|
|
461
|
+
person(data) {
|
|
462
|
+
return this.add({
|
|
463
|
+
"@context": "https://schema.org",
|
|
464
|
+
"@type": "Person",
|
|
465
|
+
name: data.name,
|
|
466
|
+
url: data.url,
|
|
467
|
+
image: data.image,
|
|
468
|
+
jobTitle: data.jobTitle,
|
|
469
|
+
worksFor: data.organization ? {
|
|
470
|
+
"@type": "Organization",
|
|
471
|
+
name: data.organization
|
|
472
|
+
} : void 0,
|
|
473
|
+
sameAs: data.socialLinks
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Build JSON-LD script tag
|
|
478
|
+
*/
|
|
479
|
+
build() {
|
|
480
|
+
if (this.schemas.length === 0) {
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
483
|
+
const data = this.schemas.length === 1 ? this.schemas[0] : this.schemas;
|
|
484
|
+
return {
|
|
485
|
+
script: {
|
|
486
|
+
type: "application/ld+json",
|
|
487
|
+
text: JSON.stringify(data, null, 2)
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Build as JSON string
|
|
493
|
+
*/
|
|
494
|
+
toJSON() {
|
|
495
|
+
const data = this.schemas.length === 1 ? this.schemas[0] : this.schemas;
|
|
496
|
+
return JSON.stringify(data, null, 2);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Clear all schemas
|
|
500
|
+
*/
|
|
501
|
+
clear() {
|
|
502
|
+
this.schemas = [];
|
|
503
|
+
return this;
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
function createStructuredData() {
|
|
507
|
+
return new StructuredDataBuilder();
|
|
508
|
+
}
|
|
509
|
+
function generateStructuredData(type, data) {
|
|
510
|
+
const builder = new StructuredDataBuilder();
|
|
511
|
+
switch (type) {
|
|
512
|
+
case "organization":
|
|
513
|
+
builder.organization(data);
|
|
514
|
+
break;
|
|
515
|
+
case "website":
|
|
516
|
+
builder.website(data);
|
|
517
|
+
break;
|
|
518
|
+
case "article":
|
|
519
|
+
builder.article(data);
|
|
520
|
+
break;
|
|
521
|
+
case "product":
|
|
522
|
+
builder.product(data);
|
|
523
|
+
break;
|
|
524
|
+
case "breadcrumb":
|
|
525
|
+
builder.breadcrumb(data);
|
|
526
|
+
break;
|
|
527
|
+
case "faq":
|
|
528
|
+
builder.faq(data);
|
|
529
|
+
break;
|
|
530
|
+
case "person":
|
|
531
|
+
builder.person(data);
|
|
532
|
+
break;
|
|
533
|
+
default:
|
|
534
|
+
builder.add(data);
|
|
535
|
+
}
|
|
536
|
+
return builder.build();
|
|
537
|
+
}
|
|
538
|
+
export {
|
|
539
|
+
MetaBuilder,
|
|
540
|
+
SitemapGenerator,
|
|
541
|
+
StructuredDataBuilder,
|
|
542
|
+
createMetaBuilder,
|
|
543
|
+
createSitemapGenerator,
|
|
544
|
+
createStructuredData,
|
|
545
|
+
generateMeta,
|
|
546
|
+
generateSitemap,
|
|
547
|
+
generateStructuredData
|
|
548
|
+
};
|
|
549
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coherent.js/seo",
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
|
+
"description": "SEO utilities for Coherent.js applications",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js",
|
|
9
|
+
"./meta": "./dist/meta.js",
|
|
10
|
+
"./sitemap": "./dist/sitemap.js",
|
|
11
|
+
"./structured-data": "./dist/structured-data.js"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"coherent",
|
|
15
|
+
"seo",
|
|
16
|
+
"meta-tags",
|
|
17
|
+
"sitemap",
|
|
18
|
+
"structured-data"
|
|
19
|
+
],
|
|
20
|
+
"author": "Coherent.js Team",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@coherent.js/core": "1.0.0-beta.2"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/Tomdrouv1/coherent.js.git"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"types": "./types/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md",
|
|
36
|
+
"types/"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "node build.mjs",
|
|
40
|
+
"clean": "rm -rf dist"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coherent.js SEO TypeScript Definitions
|
|
3
|
+
* @module @coherent.js/seo
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ===== Meta Builder Types =====
|
|
7
|
+
|
|
8
|
+
export interface MetaTags {
|
|
9
|
+
title?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
keywords?: string | string[];
|
|
12
|
+
author?: string;
|
|
13
|
+
robots?: string;
|
|
14
|
+
canonical?: string;
|
|
15
|
+
viewport?: string;
|
|
16
|
+
charset?: string;
|
|
17
|
+
language?: string;
|
|
18
|
+
themeColor?: string;
|
|
19
|
+
// Open Graph
|
|
20
|
+
ogTitle?: string;
|
|
21
|
+
ogDescription?: string;
|
|
22
|
+
ogImage?: string;
|
|
23
|
+
ogUrl?: string;
|
|
24
|
+
ogType?: string;
|
|
25
|
+
ogSiteName?: string;
|
|
26
|
+
ogLocale?: string;
|
|
27
|
+
// Twitter Card
|
|
28
|
+
twitterCard?: 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
29
|
+
twitterSite?: string;
|
|
30
|
+
twitterCreator?: string;
|
|
31
|
+
twitterTitle?: string;
|
|
32
|
+
twitterDescription?: string;
|
|
33
|
+
twitterImage?: string;
|
|
34
|
+
// Custom meta tags
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class MetaBuilder {
|
|
39
|
+
constructor(tags?: MetaTags);
|
|
40
|
+
setTitle(title: string): this;
|
|
41
|
+
setDescription(description: string): this;
|
|
42
|
+
setKeywords(keywords: string | string[]): this;
|
|
43
|
+
setAuthor(author: string): this;
|
|
44
|
+
setRobots(robots: string): this;
|
|
45
|
+
setCanonical(url: string): this;
|
|
46
|
+
setViewport(viewport: string): this;
|
|
47
|
+
setOpenGraph(tags: Partial<MetaTags>): this;
|
|
48
|
+
setTwitterCard(tags: Partial<MetaTags>): this;
|
|
49
|
+
addCustomTag(name: string, content: string, type?: 'name' | 'property'): this;
|
|
50
|
+
build(): object;
|
|
51
|
+
render(): object;
|
|
52
|
+
toHTML(): string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function createMetaBuilder(tags?: MetaTags): MetaBuilder;
|
|
56
|
+
export function generateMeta(tags: MetaTags): object;
|
|
57
|
+
|
|
58
|
+
// ===== Sitemap Generator Types =====
|
|
59
|
+
|
|
60
|
+
export interface SitemapEntry {
|
|
61
|
+
url: string;
|
|
62
|
+
lastmod?: string | Date;
|
|
63
|
+
changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
|
|
64
|
+
priority?: number;
|
|
65
|
+
images?: Array<{
|
|
66
|
+
loc: string;
|
|
67
|
+
title?: string;
|
|
68
|
+
caption?: string;
|
|
69
|
+
}>;
|
|
70
|
+
videos?: Array<{
|
|
71
|
+
thumbnail_loc: string;
|
|
72
|
+
title: string;
|
|
73
|
+
description: string;
|
|
74
|
+
content_loc?: string;
|
|
75
|
+
player_loc?: string;
|
|
76
|
+
}>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface SitemapOptions {
|
|
80
|
+
hostname: string;
|
|
81
|
+
cacheTime?: number;
|
|
82
|
+
xmlNs?: Record<string, string>;
|
|
83
|
+
xslUrl?: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export class SitemapGenerator {
|
|
87
|
+
constructor(options: SitemapOptions);
|
|
88
|
+
addUrl(entry: SitemapEntry): this;
|
|
89
|
+
addUrls(entries: SitemapEntry[]): this;
|
|
90
|
+
removeUrl(url: string): this;
|
|
91
|
+
generate(): string;
|
|
92
|
+
toXML(): string;
|
|
93
|
+
toJSON(): SitemapEntry[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function createSitemapGenerator(options: SitemapOptions): SitemapGenerator;
|
|
97
|
+
export function generateSitemap(entries: SitemapEntry[], options: SitemapOptions): string;
|
|
98
|
+
|
|
99
|
+
// ===== Structured Data Types =====
|
|
100
|
+
|
|
101
|
+
export type StructuredDataType =
|
|
102
|
+
| 'Article'
|
|
103
|
+
| 'BlogPosting'
|
|
104
|
+
| 'NewsArticle'
|
|
105
|
+
| 'WebPage'
|
|
106
|
+
| 'WebSite'
|
|
107
|
+
| 'Organization'
|
|
108
|
+
| 'Person'
|
|
109
|
+
| 'Product'
|
|
110
|
+
| 'Review'
|
|
111
|
+
| 'Event'
|
|
112
|
+
| 'Recipe'
|
|
113
|
+
| 'BreadcrumbList'
|
|
114
|
+
| 'LocalBusiness'
|
|
115
|
+
| 'FAQPage'
|
|
116
|
+
| 'HowTo'
|
|
117
|
+
| 'VideoObject'
|
|
118
|
+
| 'ImageObject';
|
|
119
|
+
|
|
120
|
+
export interface StructuredData {
|
|
121
|
+
'@context': string;
|
|
122
|
+
'@type': StructuredDataType | StructuredDataType[];
|
|
123
|
+
[key: string]: any;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class StructuredDataBuilder {
|
|
127
|
+
constructor(type: StructuredDataType);
|
|
128
|
+
setType(type: StructuredDataType): this;
|
|
129
|
+
setProperty(key: string, value: any): this;
|
|
130
|
+
setProperties(properties: Record<string, any>): this;
|
|
131
|
+
addToArray(key: string, value: any): this;
|
|
132
|
+
build(): StructuredData;
|
|
133
|
+
toJSON(): string;
|
|
134
|
+
toJSONLD(): object;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function createStructuredData(type: StructuredDataType, properties?: Record<string, any>): StructuredDataBuilder;
|
|
138
|
+
export function generateStructuredData(type: StructuredDataType, properties: Record<string, any>): StructuredData;
|
|
139
|
+
|
|
140
|
+
// Helper types for common structured data
|
|
141
|
+
|
|
142
|
+
export interface ArticleData {
|
|
143
|
+
headline: string;
|
|
144
|
+
image: string | string[];
|
|
145
|
+
datePublished: string;
|
|
146
|
+
dateModified?: string;
|
|
147
|
+
author: {
|
|
148
|
+
'@type': 'Person' | 'Organization';
|
|
149
|
+
name: string;
|
|
150
|
+
};
|
|
151
|
+
publisher: {
|
|
152
|
+
'@type': 'Organization';
|
|
153
|
+
name: string;
|
|
154
|
+
logo: {
|
|
155
|
+
'@type': 'ImageObject';
|
|
156
|
+
url: string;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
description?: string;
|
|
160
|
+
mainEntityOfPage?: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface ProductData {
|
|
164
|
+
name: string;
|
|
165
|
+
image: string | string[];
|
|
166
|
+
description: string;
|
|
167
|
+
brand?: {
|
|
168
|
+
'@type': 'Brand';
|
|
169
|
+
name: string;
|
|
170
|
+
};
|
|
171
|
+
offers?: {
|
|
172
|
+
'@type': 'Offer';
|
|
173
|
+
price: number;
|
|
174
|
+
priceCurrency: string;
|
|
175
|
+
availability?: string;
|
|
176
|
+
url?: string;
|
|
177
|
+
};
|
|
178
|
+
aggregateRating?: {
|
|
179
|
+
'@type': 'AggregateRating';
|
|
180
|
+
ratingValue: number;
|
|
181
|
+
reviewCount: number;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface BreadcrumbData {
|
|
186
|
+
itemListElement: Array<{
|
|
187
|
+
'@type': 'ListItem';
|
|
188
|
+
position: number;
|
|
189
|
+
name: string;
|
|
190
|
+
item?: string;
|
|
191
|
+
}>;
|
|
192
|
+
}
|