@prenta/plugin-seo 0.1.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/CHANGELOG.md +274 -0
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/__tests__/audit-fixes.test.d.ts +2 -0
- package/dist/__tests__/audit-fixes.test.d.ts.map +1 -0
- package/dist/__tests__/audit-fixes.test.js +162 -0
- package/dist/__tests__/audit-fixes.test.js.map +1 -0
- package/dist/__tests__/canonical.test.d.ts +2 -0
- package/dist/__tests__/canonical.test.d.ts.map +1 -0
- package/dist/__tests__/canonical.test.js +67 -0
- package/dist/__tests__/canonical.test.js.map +1 -0
- package/dist/__tests__/hooks.test.d.ts +2 -0
- package/dist/__tests__/hooks.test.d.ts.map +1 -0
- package/dist/__tests__/hooks.test.js +106 -0
- package/dist/__tests__/hooks.test.js.map +1 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +43 -0
- package/dist/__tests__/index.test.js.map +1 -0
- package/dist/__tests__/link-health.test.d.ts +2 -0
- package/dist/__tests__/link-health.test.d.ts.map +1 -0
- package/dist/__tests__/link-health.test.js +140 -0
- package/dist/__tests__/link-health.test.js.map +1 -0
- package/dist/__tests__/og-image.test.d.ts +2 -0
- package/dist/__tests__/og-image.test.d.ts.map +1 -0
- package/dist/__tests__/og-image.test.js +45 -0
- package/dist/__tests__/og-image.test.js.map +1 -0
- package/dist/__tests__/robots.test.d.ts +2 -0
- package/dist/__tests__/robots.test.d.ts.map +1 -0
- package/dist/__tests__/robots.test.js +27 -0
- package/dist/__tests__/robots.test.js.map +1 -0
- package/dist/__tests__/schema-composer.test.d.ts +2 -0
- package/dist/__tests__/schema-composer.test.d.ts.map +1 -0
- package/dist/__tests__/schema-composer.test.js +47 -0
- package/dist/__tests__/schema-composer.test.js.map +1 -0
- package/dist/__tests__/schema-validator.test.d.ts +2 -0
- package/dist/__tests__/schema-validator.test.d.ts.map +1 -0
- package/dist/__tests__/schema-validator.test.js +129 -0
- package/dist/__tests__/schema-validator.test.js.map +1 -0
- package/dist/__tests__/sitemap.test.d.ts +2 -0
- package/dist/__tests__/sitemap.test.d.ts.map +1 -0
- package/dist/__tests__/sitemap.test.js +196 -0
- package/dist/__tests__/sitemap.test.js.map +1 -0
- package/dist/admin/GooglePreview.d.ts +9 -0
- package/dist/admin/GooglePreview.d.ts.map +1 -0
- package/dist/admin/GooglePreview.js +68 -0
- package/dist/admin/GooglePreview.js.map +1 -0
- package/dist/admin/SEOPanel.d.ts +11 -0
- package/dist/admin/SEOPanel.d.ts.map +1 -0
- package/dist/admin/SEOPanel.js +76 -0
- package/dist/admin/SEOPanel.js.map +1 -0
- package/dist/admin/SchemaPreview.d.ts +7 -0
- package/dist/admin/SchemaPreview.d.ts.map +1 -0
- package/dist/admin/SchemaPreview.js +93 -0
- package/dist/admin/SchemaPreview.js.map +1 -0
- package/dist/canonical/index.d.ts +16 -0
- package/dist/canonical/index.d.ts.map +1 -0
- package/dist/canonical/index.js +77 -0
- package/dist/canonical/index.js.map +1 -0
- package/dist/collections.d.ts +3 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +2 -0
- package/dist/collections.js.map +1 -0
- package/dist/fields.d.ts +3 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +115 -0
- package/dist/fields.js.map +1 -0
- package/dist/hooks.d.ts +15 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +20 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/link-health/index.d.ts +48 -0
- package/dist/link-health/index.d.ts.map +1 -0
- package/dist/link-health/index.js +171 -0
- package/dist/link-health/index.js.map +1 -0
- package/dist/og-image/index.d.ts +11 -0
- package/dist/og-image/index.d.ts.map +1 -0
- package/dist/og-image/index.js +28 -0
- package/dist/og-image/index.js.map +1 -0
- package/dist/robots/index.d.ts +14 -0
- package/dist/robots/index.d.ts.map +1 -0
- package/dist/robots/index.js +45 -0
- package/dist/robots/index.js.map +1 -0
- package/dist/schema/auto-detect.d.ts +3 -0
- package/dist/schema/auto-detect.d.ts.map +1 -0
- package/dist/schema/auto-detect.js +3 -0
- package/dist/schema/auto-detect.js.map +1 -0
- package/dist/schema/composer.d.ts +15 -0
- package/dist/schema/composer.d.ts.map +1 -0
- package/dist/schema/composer.js +82 -0
- package/dist/schema/composer.js.map +1 -0
- package/dist/schema/registry.d.ts +170 -0
- package/dist/schema/registry.d.ts.map +1 -0
- package/dist/schema/registry.js +2 -0
- package/dist/schema/registry.js.map +1 -0
- package/dist/schema/validator.d.ts +23 -0
- package/dist/schema/validator.d.ts.map +1 -0
- package/dist/schema/validator.js +148 -0
- package/dist/schema/validator.js.map +1 -0
- package/dist/sitemap/index.d.ts +110 -0
- package/dist/sitemap/index.d.ts.map +1 -0
- package/dist/sitemap/index.js +228 -0
- package/dist/sitemap/index.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const REQUIRED_FIELDS = {
|
|
2
|
+
Article: ['headline', 'author', 'datePublished'],
|
|
3
|
+
WebPage: ['name'],
|
|
4
|
+
Person: ['name'],
|
|
5
|
+
Organization: ['name'],
|
|
6
|
+
Event: ['name', 'startDate'],
|
|
7
|
+
FAQPage: ['mainEntity'],
|
|
8
|
+
Service: ['name'],
|
|
9
|
+
JobPosting: ['title', 'datePosted', 'hiringOrganization'],
|
|
10
|
+
LocalBusiness: ['name', 'address'],
|
|
11
|
+
Review: ['itemReviewed', 'author', 'reviewRating'],
|
|
12
|
+
Product: ['name'],
|
|
13
|
+
};
|
|
14
|
+
const RECOMMENDED_FIELDS = {
|
|
15
|
+
Article: ['image', 'publisher', 'dateModified', 'description'],
|
|
16
|
+
WebPage: ['description', 'url'],
|
|
17
|
+
Person: ['image', 'url'],
|
|
18
|
+
Organization: ['logo', 'url'],
|
|
19
|
+
Event: ['endDate', 'location', 'description', 'image'],
|
|
20
|
+
FAQPage: [],
|
|
21
|
+
Service: ['provider', 'description'],
|
|
22
|
+
JobPosting: ['description', 'employmentType', 'baseSalary', 'validThrough'],
|
|
23
|
+
LocalBusiness: ['telephone', 'openingHours', 'geo'],
|
|
24
|
+
Review: ['reviewBody', 'datePublished'],
|
|
25
|
+
Product: ['image', 'description', 'offers', 'brand'],
|
|
26
|
+
};
|
|
27
|
+
/** Validates a JSON-LD schema object against Schema.org requirements. */
|
|
28
|
+
export function validateSchema(schema) {
|
|
29
|
+
const errors = [];
|
|
30
|
+
const type = schema['@type'];
|
|
31
|
+
if (!schema['@context']) {
|
|
32
|
+
errors.push({
|
|
33
|
+
field: '@context',
|
|
34
|
+
message: 'Missing @context — should be "https://schema.org"',
|
|
35
|
+
severity: 'error',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (!type) {
|
|
39
|
+
errors.push({
|
|
40
|
+
field: '@type',
|
|
41
|
+
message: 'Missing @type — every schema object must declare a type',
|
|
42
|
+
severity: 'error',
|
|
43
|
+
});
|
|
44
|
+
return { valid: false, errors };
|
|
45
|
+
}
|
|
46
|
+
const required = REQUIRED_FIELDS[type] ?? [];
|
|
47
|
+
for (const field of required) {
|
|
48
|
+
if (schema[field] === undefined || schema[field] === null || schema[field] === '') {
|
|
49
|
+
errors.push({
|
|
50
|
+
field,
|
|
51
|
+
message: `Required field "${field}" is missing for type ${type}`,
|
|
52
|
+
severity: 'error',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const recommended = RECOMMENDED_FIELDS[type] ?? [];
|
|
57
|
+
for (const field of recommended) {
|
|
58
|
+
if (schema[field] === undefined || schema[field] === null || schema[field] === '') {
|
|
59
|
+
errors.push({
|
|
60
|
+
field,
|
|
61
|
+
message: `Recommended field "${field}" is missing for type ${type}`,
|
|
62
|
+
severity: 'warning',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (type === 'Article') {
|
|
67
|
+
const headline = schema['headline'];
|
|
68
|
+
if (typeof headline === 'string' && headline.length > 110) {
|
|
69
|
+
errors.push({
|
|
70
|
+
field: 'headline',
|
|
71
|
+
message: 'Headline exceeds 110 characters — may be truncated in search results',
|
|
72
|
+
severity: 'warning',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (type === 'FAQPage' && Array.isArray(schema['mainEntity'])) {
|
|
77
|
+
const questions = schema['mainEntity'];
|
|
78
|
+
for (let i = 0; i < questions.length; i++) {
|
|
79
|
+
const q = questions[i];
|
|
80
|
+
if (q['@type'] !== 'Question') {
|
|
81
|
+
errors.push({
|
|
82
|
+
field: `mainEntity[${i}].@type`,
|
|
83
|
+
message: 'FAQ items must have @type "Question"',
|
|
84
|
+
severity: 'error',
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (!q['name']) {
|
|
88
|
+
errors.push({
|
|
89
|
+
field: `mainEntity[${i}].name`,
|
|
90
|
+
message: 'FAQ question is missing the "name" field (the question text)',
|
|
91
|
+
severity: 'error',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const answer = q['acceptedAnswer'];
|
|
95
|
+
if (!answer?.['text']) {
|
|
96
|
+
errors.push({
|
|
97
|
+
field: `mainEntity[${i}].acceptedAnswer.text`,
|
|
98
|
+
message: 'FAQ answer is missing the "text" field',
|
|
99
|
+
severity: 'error',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const hasErrors = errors.some((e) => e.severity === 'error');
|
|
105
|
+
return { valid: !hasErrors, errors };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Validates emitted JSON-LD that may be a single node, an array of nodes, or a
|
|
109
|
+
* `@graph` wrapper (`{ '@context', '@graph': [...] }`) — the shape the compose
|
|
110
|
+
* path produces. Each node is checked with {@link validateSchema} and its field
|
|
111
|
+
* paths are prefixed with the node's position so a caller can pinpoint which
|
|
112
|
+
* node in the graph is missing a required field.
|
|
113
|
+
*
|
|
114
|
+
* This is the safety net that connects the validator to the compose path: nodes
|
|
115
|
+
* missing required fields are surfaced as errors instead of silently shipping
|
|
116
|
+
* invalid structured data.
|
|
117
|
+
*/
|
|
118
|
+
export function validateSchemaGraph(input) {
|
|
119
|
+
let graph;
|
|
120
|
+
let context;
|
|
121
|
+
if (Array.isArray(input)) {
|
|
122
|
+
graph = input;
|
|
123
|
+
context = undefined;
|
|
124
|
+
}
|
|
125
|
+
else if (Array.isArray(input['@graph'])) {
|
|
126
|
+
graph = input['@graph'];
|
|
127
|
+
context = input['@context'];
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Not a graph/array — validate the single node directly.
|
|
131
|
+
return validateSchema(input);
|
|
132
|
+
}
|
|
133
|
+
const errors = [];
|
|
134
|
+
graph.forEach((node, i) => {
|
|
135
|
+
// A `@graph` shares a single top-level `@context`; don't flag every node for
|
|
136
|
+
// a missing `@context` when the wrapper provides one.
|
|
137
|
+
const nodeForCheck = context !== undefined && node['@context'] === undefined
|
|
138
|
+
? { ...node, '@context': context }
|
|
139
|
+
: node;
|
|
140
|
+
const result = validateSchema(nodeForCheck);
|
|
141
|
+
for (const err of result.errors) {
|
|
142
|
+
errors.push({ ...err, field: `@graph[${i}].${err.field}` });
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const hasErrors = errors.some((e) => e.severity === 'error');
|
|
146
|
+
return { valid: !hasErrors, errors };
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/schema/validator.ts"],"names":[],"mappings":"AASA,MAAM,eAAe,GAA6B;IAChD,OAAO,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,eAAe,CAAC;IAChD,OAAO,EAAE,CA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AAC,YAAY,CAAC,CAAA;QAC3C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;QAC7D,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAA;IAC5D,OAAO,EAAE,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,CAAA;AACtC,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export interface SitemapEntry {
|
|
2
|
+
loc: string;
|
|
3
|
+
lastmod?: string;
|
|
4
|
+
changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
|
|
5
|
+
priority?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Google rejects a sitemap file with more than 50,000 URLs or larger than 50 MB
|
|
9
|
+
* uncompressed. `generateCollectionSitemap` enforces both — a consumer feeding
|
|
10
|
+
* it an entire collection must paginate upstream (mirrors the core route, which
|
|
11
|
+
* splits at SITEMAP_PAGE_SIZE) rather than emit an oversized file Google drops.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SITEMAP_MAX_URLS = 50000;
|
|
14
|
+
export declare const SITEMAP_MAX_BYTES: number;
|
|
15
|
+
export interface ImageSitemapEntry {
|
|
16
|
+
pageUrl: string;
|
|
17
|
+
images: Array<{
|
|
18
|
+
loc: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
caption?: string;
|
|
21
|
+
geoLocation?: string;
|
|
22
|
+
license?: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export interface VideoSitemapEntry {
|
|
26
|
+
pageUrl: string;
|
|
27
|
+
video: {
|
|
28
|
+
thumbnailLoc: string;
|
|
29
|
+
title: string;
|
|
30
|
+
description: string;
|
|
31
|
+
contentLoc?: string;
|
|
32
|
+
playerLoc?: string;
|
|
33
|
+
duration?: number;
|
|
34
|
+
publicationDate?: string;
|
|
35
|
+
familyFriendly?: boolean;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface NewsSitemapEntry {
|
|
39
|
+
loc: string;
|
|
40
|
+
news: {
|
|
41
|
+
publicationName: string;
|
|
42
|
+
publicationLanguage: string;
|
|
43
|
+
publicationDate: string;
|
|
44
|
+
title: string;
|
|
45
|
+
keywords?: string[];
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export interface HreflangEntry {
|
|
49
|
+
loc: string;
|
|
50
|
+
alternates: Array<{
|
|
51
|
+
hreflang: string;
|
|
52
|
+
href: string;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
export interface CollectionSitemapConfig {
|
|
56
|
+
slug: string;
|
|
57
|
+
urlPrefix?: string;
|
|
58
|
+
type?: 'page' | 'post';
|
|
59
|
+
sitemapPriority?: number;
|
|
60
|
+
sitemapChangeFreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
|
|
61
|
+
excludeFromSitemap?: boolean;
|
|
62
|
+
archivePath?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The newest child entry's last-modified timestamp (ISO 8601). Used as the
|
|
65
|
+
* `<lastmod>` for this collection in the sitemap index. Prefer an accurate
|
|
66
|
+
* value from the collection's most-recently-updated document — a lastmod that
|
|
67
|
+
* changes on every fetch trains crawlers to ignore the signal.
|
|
68
|
+
*/
|
|
69
|
+
lastmod?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Build the public URL for a document given its collection config and slug.
|
|
73
|
+
*
|
|
74
|
+
* Delegates to cms-core's `resolveDocumentUrl` — the same authority the CMS
|
|
75
|
+
* sitemap route uses — so the two can never disagree (issue #771: slug-based
|
|
76
|
+
* URLs emitted `/home` for the root page instead of `/`). Precedence:
|
|
77
|
+
* - explicit `path` (the document's resolved route, e.g. `data.path`) -> `{baseUrl}{path}`
|
|
78
|
+
* - root slugs (`home`, `index`, empty) -> `{baseUrl}` (the site root)
|
|
79
|
+
* - Pages (urlPrefix: "") -> `{baseUrl}/{slug}`
|
|
80
|
+
* - Posts (urlPrefix: "blog") -> `{baseUrl}/blog/{slug}`
|
|
81
|
+
*/
|
|
82
|
+
export declare function buildDocumentUrl(baseUrl: string, urlPrefix: string | undefined, slug: string, path?: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Generates a sitemap index XML referencing per-collection sitemaps.
|
|
85
|
+
*
|
|
86
|
+
* Child URLs follow the same Yoast-style naming the core route serves
|
|
87
|
+
* (`{base}/{name}-sitemap.xml`). `<lastmod>` is derived from each collection's
|
|
88
|
+
* newest child entry (`CollectionSitemapConfig.lastmod`) and omitted when
|
|
89
|
+
* unknown — never stamped with `Date.now()`, which would churn on every fetch
|
|
90
|
+
* and train crawlers to ignore lastmod entirely.
|
|
91
|
+
*/
|
|
92
|
+
export declare function generateSitemapIndex(collections: (string | CollectionSitemapConfig)[], baseUrl: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Generates a sitemap XML for a collection's documents.
|
|
95
|
+
* When `collectionConfig` is provided, document slugs are resolved to full URLs
|
|
96
|
+
* using the collection's `urlPrefix` (root slugs — `home`, `index` — resolve to
|
|
97
|
+
* the site root, never `/home`). Documents with an explicit route path
|
|
98
|
+
* (`data.path`) should pass it as a root-relative `loc` (`/...`) instead of the
|
|
99
|
+
* slug. Archive pages are included for post-type collections.
|
|
100
|
+
*/
|
|
101
|
+
export declare function generateCollectionSitemap(entries: SitemapEntry[], baseUrl: string, collectionConfig?: CollectionSitemapConfig): string;
|
|
102
|
+
/** Generates a Google Image sitemap extension. */
|
|
103
|
+
export declare function generateImageSitemap(entries: ImageSitemapEntry[]): string;
|
|
104
|
+
/** Generates a Google Video sitemap extension. */
|
|
105
|
+
export declare function generateVideoSitemap(entries: VideoSitemapEntry[]): string;
|
|
106
|
+
/** Generates a Google News sitemap. */
|
|
107
|
+
export declare function generateNewsSitemap(entries: NewsSitemapEntry[]): string;
|
|
108
|
+
/** Generates a sitemap with hreflang annotations for multilingual content. */
|
|
109
|
+
export declare function generateHreflangSitemap(entries: HreflangEntry[]): string;
|
|
110
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sitemap/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAA;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAS,CAAA;AACtC,eAAO,MAAM,iBAAiB,QAAmB,CAAA;AAEjD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,KAAK,CAAC;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB,CAAC,CAAA;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAA;QACpB,KAAK,EAAE,MAAM,CAAA;QACb,WAAW,EAAE,MAAM,CAAA;QACnB,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,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CAAC,EAAE,EACjD,OAAO,EAAE,MAAM,GACd,MAAM,CAsBR;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,YAAY,EAAE,EACvB,OAAO,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,uBAAuB,GACzC,MAAM,CA8DR;AAED,kDAAkD;AAClD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAwBzE;AAED,kDAAkD;AAClD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,MAAM,CA2BzE;AAED,uCAAuC;AACvC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAuBvE;AAED,8EAA8E;AAC9E,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,MAAM,CAkBxE"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { sitemapBaseName, collectionSitemapFilename, resolveDocumentUrl } from '@prenta/core';
|
|
2
|
+
/**
|
|
3
|
+
* Google rejects a sitemap file with more than 50,000 URLs or larger than 50 MB
|
|
4
|
+
* uncompressed. `generateCollectionSitemap` enforces both — a consumer feeding
|
|
5
|
+
* it an entire collection must paginate upstream (mirrors the core route, which
|
|
6
|
+
* splits at SITEMAP_PAGE_SIZE) rather than emit an oversized file Google drops.
|
|
7
|
+
*/
|
|
8
|
+
export const SITEMAP_MAX_URLS = 50_000;
|
|
9
|
+
export const SITEMAP_MAX_BYTES = 50 * 1024 * 1024;
|
|
10
|
+
function xmlEscape(str) {
|
|
11
|
+
return str
|
|
12
|
+
.replace(/&/g, '&')
|
|
13
|
+
.replace(/</g, '<')
|
|
14
|
+
.replace(/>/g, '>')
|
|
15
|
+
.replace(/"/g, '"')
|
|
16
|
+
.replace(/'/g, ''');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build the public URL for a document given its collection config and slug.
|
|
20
|
+
*
|
|
21
|
+
* Delegates to cms-core's `resolveDocumentUrl` — the same authority the CMS
|
|
22
|
+
* sitemap route uses — so the two can never disagree (issue #771: slug-based
|
|
23
|
+
* URLs emitted `/home` for the root page instead of `/`). Precedence:
|
|
24
|
+
* - explicit `path` (the document's resolved route, e.g. `data.path`) -> `{baseUrl}{path}`
|
|
25
|
+
* - root slugs (`home`, `index`, empty) -> `{baseUrl}` (the site root)
|
|
26
|
+
* - Pages (urlPrefix: "") -> `{baseUrl}/{slug}`
|
|
27
|
+
* - Posts (urlPrefix: "blog") -> `{baseUrl}/blog/{slug}`
|
|
28
|
+
*/
|
|
29
|
+
export function buildDocumentUrl(baseUrl, urlPrefix, slug, path) {
|
|
30
|
+
return resolveDocumentUrl({
|
|
31
|
+
siteUrl: baseUrl,
|
|
32
|
+
urlPrefix,
|
|
33
|
+
slug,
|
|
34
|
+
data: path ? { path } : undefined,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Generates a sitemap index XML referencing per-collection sitemaps.
|
|
39
|
+
*
|
|
40
|
+
* Child URLs follow the same Yoast-style naming the core route serves
|
|
41
|
+
* (`{base}/{name}-sitemap.xml`). `<lastmod>` is derived from each collection's
|
|
42
|
+
* newest child entry (`CollectionSitemapConfig.lastmod`) and omitted when
|
|
43
|
+
* unknown — never stamped with `Date.now()`, which would churn on every fetch
|
|
44
|
+
* and train crawlers to ignore lastmod entirely.
|
|
45
|
+
*/
|
|
46
|
+
export function generateSitemapIndex(collections, baseUrl) {
|
|
47
|
+
const base = baseUrl.replace(/\/$/, '');
|
|
48
|
+
const sitemaps = collections
|
|
49
|
+
.filter((col) => {
|
|
50
|
+
if (typeof col === 'string')
|
|
51
|
+
return true;
|
|
52
|
+
return !col.excludeFromSitemap;
|
|
53
|
+
})
|
|
54
|
+
.map((col) => {
|
|
55
|
+
const cfg = typeof col === 'string' ? { slug: col } : col;
|
|
56
|
+
const baseName = sitemapBaseName({ slug: cfg.slug, type: cfg.type });
|
|
57
|
+
const loc = `${base}/${collectionSitemapFilename(baseName, 0)}`;
|
|
58
|
+
let xml = ` <sitemap>\n <loc>${xmlEscape(loc)}</loc>`;
|
|
59
|
+
if (cfg.lastmod)
|
|
60
|
+
xml += `\n <lastmod>${xmlEscape(cfg.lastmod)}</lastmod>`;
|
|
61
|
+
xml += '\n </sitemap>';
|
|
62
|
+
return xml;
|
|
63
|
+
})
|
|
64
|
+
.join('\n');
|
|
65
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
66
|
+
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
67
|
+
${sitemaps}
|
|
68
|
+
</sitemapindex>`;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generates a sitemap XML for a collection's documents.
|
|
72
|
+
* When `collectionConfig` is provided, document slugs are resolved to full URLs
|
|
73
|
+
* using the collection's `urlPrefix` (root slugs — `home`, `index` — resolve to
|
|
74
|
+
* the site root, never `/home`). Documents with an explicit route path
|
|
75
|
+
* (`data.path`) should pass it as a root-relative `loc` (`/...`) instead of the
|
|
76
|
+
* slug. Archive pages are included for post-type collections.
|
|
77
|
+
*/
|
|
78
|
+
export function generateCollectionSitemap(entries, baseUrl, collectionConfig) {
|
|
79
|
+
const base = baseUrl.replace(/\/$/, '');
|
|
80
|
+
const allEntries = [...entries];
|
|
81
|
+
if (collectionConfig?.archivePath && collectionConfig.type === 'post') {
|
|
82
|
+
allEntries.unshift({
|
|
83
|
+
loc: collectionConfig.archivePath,
|
|
84
|
+
changefreq: collectionConfig.sitemapChangeFreq ?? 'weekly',
|
|
85
|
+
priority: 0.6,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (allEntries.length > SITEMAP_MAX_URLS) {
|
|
89
|
+
throw new RangeError(`Sitemap would contain ${allEntries.length} URLs, exceeding the ${SITEMAP_MAX_URLS} limit. ` +
|
|
90
|
+
'Paginate the collection into multiple sitemap files.');
|
|
91
|
+
}
|
|
92
|
+
const urls = allEntries
|
|
93
|
+
.map((entry) => {
|
|
94
|
+
let loc;
|
|
95
|
+
if (entry.loc.startsWith('http')) {
|
|
96
|
+
loc = entry.loc;
|
|
97
|
+
}
|
|
98
|
+
else if (entry.loc.startsWith('/')) {
|
|
99
|
+
loc = `${base}${entry.loc}`;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Bare slug — resolve through the shared document-URL authority so
|
|
103
|
+
// root slugs (`home`, `index`) emit the site root, never `/home`.
|
|
104
|
+
loc = buildDocumentUrl(base, collectionConfig?.urlPrefix, entry.loc);
|
|
105
|
+
}
|
|
106
|
+
const changefreq = entry.changefreq ?? collectionConfig?.sitemapChangeFreq;
|
|
107
|
+
const priority = entry.priority ??
|
|
108
|
+
collectionConfig?.sitemapPriority ??
|
|
109
|
+
(collectionConfig?.type === 'page' ? 0.8 : 0.6);
|
|
110
|
+
let xml = ` <url>\n <loc>${xmlEscape(loc)}</loc>`;
|
|
111
|
+
if (entry.lastmod)
|
|
112
|
+
xml += `\n <lastmod>${xmlEscape(entry.lastmod)}</lastmod>`;
|
|
113
|
+
if (changefreq)
|
|
114
|
+
xml += `\n <changefreq>${changefreq}</changefreq>`;
|
|
115
|
+
xml += `\n <priority>${priority.toFixed(1)}</priority>`;
|
|
116
|
+
xml += '\n </url>';
|
|
117
|
+
return xml;
|
|
118
|
+
})
|
|
119
|
+
.join('\n');
|
|
120
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
121
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
122
|
+
${urls}
|
|
123
|
+
</urlset>`;
|
|
124
|
+
const bytes = new TextEncoder().encode(xml).length;
|
|
125
|
+
if (bytes > SITEMAP_MAX_BYTES) {
|
|
126
|
+
throw new RangeError(`Sitemap is ${bytes} bytes, exceeding the ${SITEMAP_MAX_BYTES}-byte (50 MB) limit. ` +
|
|
127
|
+
'Paginate the collection into multiple sitemap files.');
|
|
128
|
+
}
|
|
129
|
+
return xml;
|
|
130
|
+
}
|
|
131
|
+
/** Generates a Google Image sitemap extension. */
|
|
132
|
+
export function generateImageSitemap(entries) {
|
|
133
|
+
const urls = entries
|
|
134
|
+
.map((entry) => {
|
|
135
|
+
const images = entry.images
|
|
136
|
+
.map((img) => {
|
|
137
|
+
let xml = ` <image:image>\n <image:loc>${xmlEscape(img.loc)}</image:loc>`;
|
|
138
|
+
if (img.title)
|
|
139
|
+
xml += `\n <image:title>${xmlEscape(img.title)}</image:title>`;
|
|
140
|
+
if (img.caption)
|
|
141
|
+
xml += `\n <image:caption>${xmlEscape(img.caption)}</image:caption>`;
|
|
142
|
+
if (img.geoLocation)
|
|
143
|
+
xml += `\n <image:geo_location>${xmlEscape(img.geoLocation)}</image:geo_location>`;
|
|
144
|
+
if (img.license)
|
|
145
|
+
xml += `\n <image:license>${xmlEscape(img.license)}</image:license>`;
|
|
146
|
+
xml += '\n </image:image>';
|
|
147
|
+
return xml;
|
|
148
|
+
})
|
|
149
|
+
.join('\n');
|
|
150
|
+
return ` <url>\n <loc>${xmlEscape(entry.pageUrl)}</loc>\n${images}\n </url>`;
|
|
151
|
+
})
|
|
152
|
+
.join('\n');
|
|
153
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
154
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
155
|
+
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
|
|
156
|
+
${urls}
|
|
157
|
+
</urlset>`;
|
|
158
|
+
}
|
|
159
|
+
/** Generates a Google Video sitemap extension. */
|
|
160
|
+
export function generateVideoSitemap(entries) {
|
|
161
|
+
const urls = entries
|
|
162
|
+
.map((entry) => {
|
|
163
|
+
const v = entry.video;
|
|
164
|
+
let xml = ` <url>\n <loc>${xmlEscape(entry.pageUrl)}</loc>\n <video:video>`;
|
|
165
|
+
xml += `\n <video:thumbnail_loc>${xmlEscape(v.thumbnailLoc)}</video:thumbnail_loc>`;
|
|
166
|
+
xml += `\n <video:title>${xmlEscape(v.title)}</video:title>`;
|
|
167
|
+
xml += `\n <video:description>${xmlEscape(v.description)}</video:description>`;
|
|
168
|
+
if (v.contentLoc)
|
|
169
|
+
xml += `\n <video:content_loc>${xmlEscape(v.contentLoc)}</video:content_loc>`;
|
|
170
|
+
if (v.playerLoc)
|
|
171
|
+
xml += `\n <video:player_loc>${xmlEscape(v.playerLoc)}</video:player_loc>`;
|
|
172
|
+
if (v.duration !== undefined)
|
|
173
|
+
xml += `\n <video:duration>${v.duration}</video:duration>`;
|
|
174
|
+
if (v.publicationDate)
|
|
175
|
+
xml += `\n <video:publication_date>${xmlEscape(v.publicationDate)}</video:publication_date>`;
|
|
176
|
+
if (v.familyFriendly !== undefined)
|
|
177
|
+
xml += `\n <video:family_friendly>${v.familyFriendly ? 'yes' : 'no'}</video:family_friendly>`;
|
|
178
|
+
xml += '\n </video:video>\n </url>';
|
|
179
|
+
return xml;
|
|
180
|
+
})
|
|
181
|
+
.join('\n');
|
|
182
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
183
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
184
|
+
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
|
|
185
|
+
${urls}
|
|
186
|
+
</urlset>`;
|
|
187
|
+
}
|
|
188
|
+
/** Generates a Google News sitemap. */
|
|
189
|
+
export function generateNewsSitemap(entries) {
|
|
190
|
+
const urls = entries
|
|
191
|
+
.map((entry) => {
|
|
192
|
+
const n = entry.news;
|
|
193
|
+
let xml = ` <url>\n <loc>${xmlEscape(entry.loc)}</loc>\n <news:news>`;
|
|
194
|
+
xml += `\n <news:publication>`;
|
|
195
|
+
xml += `\n <news:name>${xmlEscape(n.publicationName)}</news:name>`;
|
|
196
|
+
xml += `\n <news:language>${xmlEscape(n.publicationLanguage)}</news:language>`;
|
|
197
|
+
xml += `\n </news:publication>`;
|
|
198
|
+
xml += `\n <news:publication_date>${xmlEscape(n.publicationDate)}</news:publication_date>`;
|
|
199
|
+
xml += `\n <news:title>${xmlEscape(n.title)}</news:title>`;
|
|
200
|
+
if (n.keywords?.length)
|
|
201
|
+
xml += `\n <news:keywords>${xmlEscape(n.keywords.join(', '))}</news:keywords>`;
|
|
202
|
+
xml += '\n </news:news>\n </url>';
|
|
203
|
+
return xml;
|
|
204
|
+
})
|
|
205
|
+
.join('\n');
|
|
206
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
207
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
208
|
+
xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
|
|
209
|
+
${urls}
|
|
210
|
+
</urlset>`;
|
|
211
|
+
}
|
|
212
|
+
/** Generates a sitemap with hreflang annotations for multilingual content. */
|
|
213
|
+
export function generateHreflangSitemap(entries) {
|
|
214
|
+
const urls = entries
|
|
215
|
+
.map((entry) => {
|
|
216
|
+
const links = entry.alternates
|
|
217
|
+
.map((alt) => ` <xhtml:link rel="alternate" hreflang="${xmlEscape(alt.hreflang)}" href="${xmlEscape(alt.href)}" />`)
|
|
218
|
+
.join('\n');
|
|
219
|
+
return ` <url>\n <loc>${xmlEscape(entry.loc)}</loc>\n${links}\n </url>`;
|
|
220
|
+
})
|
|
221
|
+
.join('\n');
|
|
222
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
223
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
224
|
+
xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
225
|
+
${urls}
|
|
226
|
+
</urlset>`;
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sitemap/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAS7F;;;;;GAKG;AACH,MAAM,CAAC,MAAM,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,CAC3G;aACA,IAAI,CAAC,IAAI,CAAC,CAAA;QACb,OAAO,qBAAqB,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,KAAK,YAAY,CAAA;IAC9E,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,OAAO;;;EAGP,IAAI;UACI,CAAA;AACV,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@prenta/plugin-seo",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/actuate-media/prenta.git",
|
|
8
|
+
"directory": "packages/plugin-seo"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"CHANGELOG.md"
|
|
26
|
+
],
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/react": "^19.0.0",
|
|
29
|
+
"typescript": "^5.7.0",
|
|
30
|
+
"vitest": "^4.1.0",
|
|
31
|
+
"@prenta/core": "0.118.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@prenta/core": ">=0.1.0",
|
|
35
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc --project tsconfig.json",
|
|
39
|
+
"type-check": "tsc --noEmit",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"clean": "rm -rf dist .turbo"
|
|
42
|
+
}
|
|
43
|
+
}
|