@nuxtjs/sitemap 8.3.1 → 8.3.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/dist/module.json +1 -1
- package/dist/utils.d.mts +94 -3
- package/dist/utils.d.ts +94 -3
- package/dist/utils.mjs +235 -1
- package/package.json +3 -3
package/dist/module.json
CHANGED
package/dist/utils.d.mts
CHANGED
|
@@ -1,8 +1,98 @@
|
|
|
1
|
-
import { SitemapUrl } from '../dist/runtime/types.js';
|
|
1
|
+
import { SitemapUrlInput, SitemapUrl } from '../dist/runtime/types.js';
|
|
2
2
|
export * from '../dist/runtime/types.js';
|
|
3
|
+
import { SitemapInput } from 'sitemapd/parse';
|
|
4
|
+
export { CollectSitemapResult, ParseSitemapOptions, SitemapCompleteness, SitemapDocument, SitemapDocumentKind, SitemapExtensions, SitemapFormat, SitemapInput, SitemapIssue, SitemapIssueCode, SitemapParseEvent, SitemapReference, SitemapUrlRecord, collectSitemap, parseSitemap } from 'sitemapd/parse';
|
|
3
5
|
export { SitemapDocumentLoadResult, SitemapDocumentLoader, SitemapLoadFailureCode, SitemapLoadRequest, SitemapLoadSource, SitemapReadOptions, SitemapReadResult, SitemapReader, SitemapReaderOptions, SitemapTargetAuthorization, SitemapTargetAuthorizer, SitemapWalkDocument, SitemapWalkDocumentVisitor, SitemapWalkFailure, SitemapWalkNonRetainedResult, SitemapWalkOptions, SitemapWalkPartialReason, SitemapWalkResult, SitemapWalkRetainedResult, createSitemapReader } from 'sitemapd';
|
|
4
6
|
export { FetchDocumentLoaderOptions, SitemapFetch, createFetchDocumentLoader } from 'sitemapd/fetch';
|
|
5
|
-
|
|
7
|
+
|
|
8
|
+
/** @deprecated Use `SitemapIssue` with `parseSitemap` or `collectSitemap`. */
|
|
9
|
+
interface SitemapWarning {
|
|
10
|
+
type: 'validation';
|
|
11
|
+
message: string;
|
|
12
|
+
context?: {
|
|
13
|
+
url?: string;
|
|
14
|
+
field?: string;
|
|
15
|
+
value?: unknown;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** @deprecated Use the tagged `CollectSitemapResult` returned by `collectSitemap`. */
|
|
19
|
+
interface SitemapParseResult {
|
|
20
|
+
urls: SitemapUrlInput[];
|
|
21
|
+
warnings: SitemapWarning[];
|
|
22
|
+
}
|
|
23
|
+
/** @deprecated Use `SitemapReference`. */
|
|
24
|
+
interface SitemapIndexEntry {
|
|
25
|
+
loc: string;
|
|
26
|
+
lastmod?: string;
|
|
27
|
+
}
|
|
28
|
+
/** @deprecated Use the tagged `CollectSitemapResult` returned by `collectSitemap`. */
|
|
29
|
+
interface SitemapIndexParseResult {
|
|
30
|
+
entries: SitemapIndexEntry[];
|
|
31
|
+
warnings: SitemapWarning[];
|
|
32
|
+
}
|
|
33
|
+
/** @deprecated Use `SitemapInput`. */
|
|
34
|
+
type SitemapXmlChunk = string | Uint8Array;
|
|
35
|
+
/** @deprecated Use `SitemapInput`. */
|
|
36
|
+
type SitemapXmlInput = SitemapInput;
|
|
37
|
+
/** @deprecated Use `ParseSitemapOptions`. */
|
|
38
|
+
interface SitemapStreamOptions {
|
|
39
|
+
maxEntryBytes?: number;
|
|
40
|
+
maxBufferBytes?: number;
|
|
41
|
+
}
|
|
42
|
+
/** @deprecated Use `SitemapParseEvent`. */
|
|
43
|
+
type SitemapXmlStreamEvent = {
|
|
44
|
+
_tag: 'url';
|
|
45
|
+
url: SitemapUrlInput;
|
|
46
|
+
} | {
|
|
47
|
+
_tag: 'warning';
|
|
48
|
+
warning: SitemapWarning;
|
|
49
|
+
};
|
|
50
|
+
/** @deprecated Use `SitemapParseEvent`. */
|
|
51
|
+
type SitemapIndexStreamEvent = {
|
|
52
|
+
_tag: 'sitemap';
|
|
53
|
+
sitemap: SitemapIndexEntry;
|
|
54
|
+
} | {
|
|
55
|
+
_tag: 'warning';
|
|
56
|
+
warning: SitemapWarning;
|
|
57
|
+
};
|
|
58
|
+
/** @deprecated Use `SitemapDocumentKind`. */
|
|
59
|
+
type SitemapKind = 'urlset' | 'index';
|
|
60
|
+
/** @deprecated Use `SitemapParseEvent`. */
|
|
61
|
+
type SitemapStreamEvent = {
|
|
62
|
+
_tag: 'kind';
|
|
63
|
+
kind: SitemapKind;
|
|
64
|
+
} | SitemapXmlStreamEvent | SitemapIndexStreamEvent;
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Use `parseSitemap` from `@nuxtjs/sitemap/utils`. Canonical
|
|
67
|
+
* streams emit `document`, `url`, `sitemap`, `issue`, and terminal `end`
|
|
68
|
+
* events. URL and sitemap payloads use `entry`.
|
|
69
|
+
*/
|
|
70
|
+
declare function parseSitemapStream(input: SitemapXmlInput, options?: SitemapStreamOptions): AsyncGenerator<SitemapStreamEvent>;
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use `parseSitemap` from `@nuxtjs/sitemap/utils` and handle
|
|
73
|
+
* events whose document kind is `urlset`.
|
|
74
|
+
*/
|
|
75
|
+
declare function parseSitemapXmlStream(input: SitemapXmlInput, options?: SitemapStreamOptions): AsyncGenerator<SitemapXmlStreamEvent>;
|
|
76
|
+
/**
|
|
77
|
+
* @deprecated Use `parseSitemap` from `@nuxtjs/sitemap/utils` and handle
|
|
78
|
+
* events whose document kind is `index`.
|
|
79
|
+
*/
|
|
80
|
+
declare function parseSitemapIndexStream(input: SitemapXmlInput, options?: SitemapStreamOptions): AsyncGenerator<SitemapIndexStreamEvent>;
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Use `collectSitemap` from `@nuxtjs/sitemap/utils` and handle
|
|
83
|
+
* its tagged result.
|
|
84
|
+
*/
|
|
85
|
+
declare function parseSitemapXml(xml: string): Promise<SitemapParseResult>;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated Use `collectSitemap` from `@nuxtjs/sitemap/utils` and handle
|
|
88
|
+
* an `index` document result.
|
|
89
|
+
*/
|
|
90
|
+
declare function parseSitemapIndex(xml: string): Promise<SitemapIndexParseResult>;
|
|
91
|
+
/**
|
|
92
|
+
* @deprecated Use `collectSitemap` from `@nuxtjs/sitemap/utils` and inspect
|
|
93
|
+
* the tagged document result.
|
|
94
|
+
*/
|
|
95
|
+
declare function isSitemapIndex(xml: string): boolean;
|
|
6
96
|
|
|
7
97
|
declare function parseHtmlExtractSitemapMeta(html: string, options?: {
|
|
8
98
|
images?: boolean;
|
|
@@ -12,4 +102,5 @@ declare function parseHtmlExtractSitemapMeta(html: string, options?: {
|
|
|
12
102
|
resolveUrl?: (s: string) => string;
|
|
13
103
|
}): Partial<SitemapUrl> | null;
|
|
14
104
|
|
|
15
|
-
export { parseHtmlExtractSitemapMeta };
|
|
105
|
+
export { isSitemapIndex, parseHtmlExtractSitemapMeta, parseSitemapIndex, parseSitemapIndexStream, parseSitemapStream, parseSitemapXml, parseSitemapXmlStream };
|
|
106
|
+
export type { SitemapIndexEntry, SitemapIndexParseResult, SitemapIndexStreamEvent, SitemapKind, SitemapParseResult, SitemapStreamEvent, SitemapStreamOptions, SitemapWarning, SitemapXmlChunk, SitemapXmlInput, SitemapXmlStreamEvent };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,8 +1,98 @@
|
|
|
1
|
-
import { SitemapUrl } from '../dist/runtime/types.js';
|
|
1
|
+
import { SitemapUrlInput, SitemapUrl } from '../dist/runtime/types.js';
|
|
2
2
|
export * from '../dist/runtime/types.js';
|
|
3
|
+
import { SitemapInput } from 'sitemapd/parse';
|
|
4
|
+
export { CollectSitemapResult, ParseSitemapOptions, SitemapCompleteness, SitemapDocument, SitemapDocumentKind, SitemapExtensions, SitemapFormat, SitemapInput, SitemapIssue, SitemapIssueCode, SitemapParseEvent, SitemapReference, SitemapUrlRecord, collectSitemap, parseSitemap } from 'sitemapd/parse';
|
|
3
5
|
export { SitemapDocumentLoadResult, SitemapDocumentLoader, SitemapLoadFailureCode, SitemapLoadRequest, SitemapLoadSource, SitemapReadOptions, SitemapReadResult, SitemapReader, SitemapReaderOptions, SitemapTargetAuthorization, SitemapTargetAuthorizer, SitemapWalkDocument, SitemapWalkDocumentVisitor, SitemapWalkFailure, SitemapWalkNonRetainedResult, SitemapWalkOptions, SitemapWalkPartialReason, SitemapWalkResult, SitemapWalkRetainedResult, createSitemapReader } from 'sitemapd';
|
|
4
6
|
export { FetchDocumentLoaderOptions, SitemapFetch, createFetchDocumentLoader } from 'sitemapd/fetch';
|
|
5
|
-
|
|
7
|
+
|
|
8
|
+
/** @deprecated Use `SitemapIssue` with `parseSitemap` or `collectSitemap`. */
|
|
9
|
+
interface SitemapWarning {
|
|
10
|
+
type: 'validation';
|
|
11
|
+
message: string;
|
|
12
|
+
context?: {
|
|
13
|
+
url?: string;
|
|
14
|
+
field?: string;
|
|
15
|
+
value?: unknown;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** @deprecated Use the tagged `CollectSitemapResult` returned by `collectSitemap`. */
|
|
19
|
+
interface SitemapParseResult {
|
|
20
|
+
urls: SitemapUrlInput[];
|
|
21
|
+
warnings: SitemapWarning[];
|
|
22
|
+
}
|
|
23
|
+
/** @deprecated Use `SitemapReference`. */
|
|
24
|
+
interface SitemapIndexEntry {
|
|
25
|
+
loc: string;
|
|
26
|
+
lastmod?: string;
|
|
27
|
+
}
|
|
28
|
+
/** @deprecated Use the tagged `CollectSitemapResult` returned by `collectSitemap`. */
|
|
29
|
+
interface SitemapIndexParseResult {
|
|
30
|
+
entries: SitemapIndexEntry[];
|
|
31
|
+
warnings: SitemapWarning[];
|
|
32
|
+
}
|
|
33
|
+
/** @deprecated Use `SitemapInput`. */
|
|
34
|
+
type SitemapXmlChunk = string | Uint8Array;
|
|
35
|
+
/** @deprecated Use `SitemapInput`. */
|
|
36
|
+
type SitemapXmlInput = SitemapInput;
|
|
37
|
+
/** @deprecated Use `ParseSitemapOptions`. */
|
|
38
|
+
interface SitemapStreamOptions {
|
|
39
|
+
maxEntryBytes?: number;
|
|
40
|
+
maxBufferBytes?: number;
|
|
41
|
+
}
|
|
42
|
+
/** @deprecated Use `SitemapParseEvent`. */
|
|
43
|
+
type SitemapXmlStreamEvent = {
|
|
44
|
+
_tag: 'url';
|
|
45
|
+
url: SitemapUrlInput;
|
|
46
|
+
} | {
|
|
47
|
+
_tag: 'warning';
|
|
48
|
+
warning: SitemapWarning;
|
|
49
|
+
};
|
|
50
|
+
/** @deprecated Use `SitemapParseEvent`. */
|
|
51
|
+
type SitemapIndexStreamEvent = {
|
|
52
|
+
_tag: 'sitemap';
|
|
53
|
+
sitemap: SitemapIndexEntry;
|
|
54
|
+
} | {
|
|
55
|
+
_tag: 'warning';
|
|
56
|
+
warning: SitemapWarning;
|
|
57
|
+
};
|
|
58
|
+
/** @deprecated Use `SitemapDocumentKind`. */
|
|
59
|
+
type SitemapKind = 'urlset' | 'index';
|
|
60
|
+
/** @deprecated Use `SitemapParseEvent`. */
|
|
61
|
+
type SitemapStreamEvent = {
|
|
62
|
+
_tag: 'kind';
|
|
63
|
+
kind: SitemapKind;
|
|
64
|
+
} | SitemapXmlStreamEvent | SitemapIndexStreamEvent;
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Use `parseSitemap` from `@nuxtjs/sitemap/utils`. Canonical
|
|
67
|
+
* streams emit `document`, `url`, `sitemap`, `issue`, and terminal `end`
|
|
68
|
+
* events. URL and sitemap payloads use `entry`.
|
|
69
|
+
*/
|
|
70
|
+
declare function parseSitemapStream(input: SitemapXmlInput, options?: SitemapStreamOptions): AsyncGenerator<SitemapStreamEvent>;
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use `parseSitemap` from `@nuxtjs/sitemap/utils` and handle
|
|
73
|
+
* events whose document kind is `urlset`.
|
|
74
|
+
*/
|
|
75
|
+
declare function parseSitemapXmlStream(input: SitemapXmlInput, options?: SitemapStreamOptions): AsyncGenerator<SitemapXmlStreamEvent>;
|
|
76
|
+
/**
|
|
77
|
+
* @deprecated Use `parseSitemap` from `@nuxtjs/sitemap/utils` and handle
|
|
78
|
+
* events whose document kind is `index`.
|
|
79
|
+
*/
|
|
80
|
+
declare function parseSitemapIndexStream(input: SitemapXmlInput, options?: SitemapStreamOptions): AsyncGenerator<SitemapIndexStreamEvent>;
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Use `collectSitemap` from `@nuxtjs/sitemap/utils` and handle
|
|
83
|
+
* its tagged result.
|
|
84
|
+
*/
|
|
85
|
+
declare function parseSitemapXml(xml: string): Promise<SitemapParseResult>;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated Use `collectSitemap` from `@nuxtjs/sitemap/utils` and handle
|
|
88
|
+
* an `index` document result.
|
|
89
|
+
*/
|
|
90
|
+
declare function parseSitemapIndex(xml: string): Promise<SitemapIndexParseResult>;
|
|
91
|
+
/**
|
|
92
|
+
* @deprecated Use `collectSitemap` from `@nuxtjs/sitemap/utils` and inspect
|
|
93
|
+
* the tagged document result.
|
|
94
|
+
*/
|
|
95
|
+
declare function isSitemapIndex(xml: string): boolean;
|
|
6
96
|
|
|
7
97
|
declare function parseHtmlExtractSitemapMeta(html: string, options?: {
|
|
8
98
|
images?: boolean;
|
|
@@ -12,4 +102,5 @@ declare function parseHtmlExtractSitemapMeta(html: string, options?: {
|
|
|
12
102
|
resolveUrl?: (s: string) => string;
|
|
13
103
|
}): Partial<SitemapUrl> | null;
|
|
14
104
|
|
|
15
|
-
export { parseHtmlExtractSitemapMeta };
|
|
105
|
+
export { isSitemapIndex, parseHtmlExtractSitemapMeta, parseSitemapIndex, parseSitemapIndexStream, parseSitemapStream, parseSitemapXml, parseSitemapXmlStream };
|
|
106
|
+
export type { SitemapIndexEntry, SitemapIndexParseResult, SitemapIndexStreamEvent, SitemapKind, SitemapParseResult, SitemapStreamEvent, SitemapStreamOptions, SitemapWarning, SitemapXmlChunk, SitemapXmlInput, SitemapXmlStreamEvent };
|
package/dist/utils.mjs
CHANGED
|
@@ -1,6 +1,240 @@
|
|
|
1
|
+
import { parseSitemap } from 'sitemapd/parse';
|
|
2
|
+
export { collectSitemap, parseSitemap } from 'sitemapd/parse';
|
|
1
3
|
export { p as parseHtmlExtractSitemapMeta } from './shared/sitemap.BoMnWHOt.mjs';
|
|
2
4
|
export { createSitemapReader } from 'sitemapd';
|
|
3
5
|
export { createFetchDocumentLoader } from 'sitemapd/fetch';
|
|
4
|
-
export { collectSitemap, parseSitemap } from 'sitemapd/parse';
|
|
5
6
|
import 'ufo';
|
|
6
7
|
import 'ultrahtml';
|
|
8
|
+
|
|
9
|
+
const CHANGE_FREQUENCIES = /* @__PURE__ */ new Set([
|
|
10
|
+
"always",
|
|
11
|
+
"hourly",
|
|
12
|
+
"daily",
|
|
13
|
+
"weekly",
|
|
14
|
+
"monthly",
|
|
15
|
+
"yearly",
|
|
16
|
+
"never"
|
|
17
|
+
]);
|
|
18
|
+
function legacyWarning(issue, kind) {
|
|
19
|
+
if (issue.code === "missing_loc") {
|
|
20
|
+
return {
|
|
21
|
+
type: "validation",
|
|
22
|
+
message: kind === "index" ? "Sitemap entry missing required loc element" : "URL entry missing required loc element",
|
|
23
|
+
...kind === "urlset" ? { context: { url: "undefined" } } : {}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (issue.code === "invalid_loc" && kind === "index") {
|
|
27
|
+
const url = String(issue.value);
|
|
28
|
+
if (URL.canParse(url))
|
|
29
|
+
return void 0;
|
|
30
|
+
return {
|
|
31
|
+
type: "validation",
|
|
32
|
+
message: "Sitemap entry has invalid URL",
|
|
33
|
+
context: { url }
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (issue.severity !== "warning" || issue.code === "invalid_loc")
|
|
37
|
+
return void 0;
|
|
38
|
+
return {
|
|
39
|
+
type: "validation",
|
|
40
|
+
message: issue.message,
|
|
41
|
+
...issue.field || issue.value !== void 0 ? {
|
|
42
|
+
context: {
|
|
43
|
+
...issue.field ? { field: issue.field } : {},
|
|
44
|
+
...issue.value !== void 0 ? { value: issue.value } : {}
|
|
45
|
+
}
|
|
46
|
+
} : {}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function legacyImages(images) {
|
|
50
|
+
return images?.map((image) => ({
|
|
51
|
+
loc: image.loc,
|
|
52
|
+
...image.caption ? { caption: image.caption } : {},
|
|
53
|
+
...image.geoLocation ? { geo_location: image.geoLocation } : {},
|
|
54
|
+
...image.title ? { title: image.title } : {},
|
|
55
|
+
...image.license ? { license: image.license } : {}
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
function legacyUrl(entry) {
|
|
59
|
+
const warnings = [];
|
|
60
|
+
const url = { loc: entry.loc };
|
|
61
|
+
if (entry.lastmod)
|
|
62
|
+
url.lastmod = entry.lastmod;
|
|
63
|
+
if (entry.changefreq) {
|
|
64
|
+
if (CHANGE_FREQUENCIES.has(entry.changefreq)) {
|
|
65
|
+
url.changefreq = entry.changefreq;
|
|
66
|
+
} else {
|
|
67
|
+
warnings.push({
|
|
68
|
+
type: "validation",
|
|
69
|
+
message: "Invalid changefreq value",
|
|
70
|
+
context: { url: entry.loc, field: "changefreq", value: entry.changefreq }
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (entry.priority !== void 0) {
|
|
75
|
+
const priority = Number.parseFloat(entry.priority);
|
|
76
|
+
if (Number.isNaN(priority)) {
|
|
77
|
+
warnings.push({
|
|
78
|
+
type: "validation",
|
|
79
|
+
message: "Invalid priority value",
|
|
80
|
+
context: { url: entry.loc, field: "priority", value: entry.priority }
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
if (priority < 0 || priority > 1) {
|
|
84
|
+
warnings.push({
|
|
85
|
+
type: "validation",
|
|
86
|
+
message: "Priority value should be between 0.0 and 1.0, clamping to valid range",
|
|
87
|
+
context: { url: entry.loc, field: "priority", value: priority }
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
url.priority = Math.max(0, Math.min(1, priority));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const extensions = entry.extensions;
|
|
94
|
+
if (extensions?.alternatives) {
|
|
95
|
+
url.alternatives = extensions.alternatives.flatMap((alternative) => {
|
|
96
|
+
if ((!alternative.rel || alternative.rel === "alternate") && alternative.hreflang)
|
|
97
|
+
return [{ hreflang: alternative.hreflang, href: alternative.href }];
|
|
98
|
+
warnings.push({
|
|
99
|
+
type: "validation",
|
|
100
|
+
message: 'Alternative link missing required rel="alternate", hreflang, or href',
|
|
101
|
+
context: { url: entry.loc, field: "link" }
|
|
102
|
+
});
|
|
103
|
+
return [];
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const images = legacyImages(extensions?.images);
|
|
107
|
+
if (images?.length)
|
|
108
|
+
url.images = images;
|
|
109
|
+
if (extensions?.videos?.length)
|
|
110
|
+
url.videos = extensions.videos;
|
|
111
|
+
if (extensions?.news)
|
|
112
|
+
url.news = extensions.news;
|
|
113
|
+
return { url, warnings };
|
|
114
|
+
}
|
|
115
|
+
function positiveOption(value, name) {
|
|
116
|
+
if (value === void 0)
|
|
117
|
+
return void 0;
|
|
118
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
119
|
+
throw new TypeError(`${name} must be a positive safe integer`);
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
function parserFailure(issue, kind, options) {
|
|
123
|
+
if (issue?.code === "empty")
|
|
124
|
+
return new Error("Empty XML input provided");
|
|
125
|
+
if (issue?.code === "decoded_limit" && options.maxBufferBytes)
|
|
126
|
+
return new Error(`Sitemap XML buffer exceeds maxBufferBytes of ${options.maxBufferBytes}`);
|
|
127
|
+
const entryLimit = issue?.message.match(/^Sitemap entry exceeds (\d+) bytes$/);
|
|
128
|
+
if (entryLimit)
|
|
129
|
+
return new Error(`Sitemap entry exceeds maxEntryBytes of ${entryLimit[1]}`);
|
|
130
|
+
if (issue?.code === "unsupported" || issue?.code === "html") {
|
|
131
|
+
return new Error(
|
|
132
|
+
kind === "index" ? "XML does not contain a valid sitemapindex element" : kind === "urlset" ? "XML does not contain a valid urlset element" : "XML does not contain a valid sitemap element"
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return new Error(`Failed to parse XML: ${issue?.message || "Malformed sitemap"}`);
|
|
136
|
+
}
|
|
137
|
+
async function* parseSitemapStreamInternal(input, options = {}, expectedKind) {
|
|
138
|
+
const maxEntryBytes = positiveOption(options.maxEntryBytes, "maxEntryBytes");
|
|
139
|
+
const maxBufferBytes = positiveOption(options.maxBufferBytes, "maxBufferBytes");
|
|
140
|
+
let kind;
|
|
141
|
+
let lastIssue;
|
|
142
|
+
let invalidUrlEntries = 0;
|
|
143
|
+
let validUrls = 0;
|
|
144
|
+
for await (const event of parseSitemap(input, {
|
|
145
|
+
...maxEntryBytes ? { maxEntryBytes } : {},
|
|
146
|
+
...maxBufferBytes ? { maxDecodedBytes: maxBufferBytes } : {}
|
|
147
|
+
})) {
|
|
148
|
+
if (event._tag === "document") {
|
|
149
|
+
if (event.format !== "xml") {
|
|
150
|
+
throw new Error(
|
|
151
|
+
expectedKind === "index" ? "XML does not contain a valid sitemapindex element" : expectedKind === "urlset" ? "XML does not contain a valid urlset element" : "XML does not contain a valid sitemap element"
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
kind = event.kind;
|
|
155
|
+
yield { _tag: "kind", kind };
|
|
156
|
+
} else if (event._tag === "issue") {
|
|
157
|
+
lastIssue = event.issue;
|
|
158
|
+
if (!kind)
|
|
159
|
+
continue;
|
|
160
|
+
if (event.issue.code === "missing_loc" && kind === "urlset")
|
|
161
|
+
invalidUrlEntries++;
|
|
162
|
+
const warning = legacyWarning(event.issue, kind);
|
|
163
|
+
if (warning)
|
|
164
|
+
yield { _tag: "warning", warning };
|
|
165
|
+
} else if (event._tag === "url") {
|
|
166
|
+
validUrls++;
|
|
167
|
+
const mapped = legacyUrl(event.entry);
|
|
168
|
+
for (const warning of mapped.warnings)
|
|
169
|
+
yield { _tag: "warning", warning };
|
|
170
|
+
yield { _tag: "url", url: mapped.url };
|
|
171
|
+
} else if (event._tag === "sitemap") {
|
|
172
|
+
if (!URL.canParse(event.entry.loc))
|
|
173
|
+
continue;
|
|
174
|
+
yield { _tag: "sitemap", sitemap: event.entry };
|
|
175
|
+
} else if (event.completeness._tag !== "complete") {
|
|
176
|
+
throw parserFailure(lastIssue, kind || expectedKind, options);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (kind === "urlset" && invalidUrlEntries > 0 && validUrls === 0) {
|
|
180
|
+
yield {
|
|
181
|
+
_tag: "warning",
|
|
182
|
+
warning: {
|
|
183
|
+
type: "validation",
|
|
184
|
+
message: "No valid URLs found in sitemap after validation"
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function* parseSitemapStream(input, options = {}) {
|
|
190
|
+
yield* parseSitemapStreamInternal(input, options);
|
|
191
|
+
}
|
|
192
|
+
async function* parseSitemapXmlStream(input, options = {}) {
|
|
193
|
+
for await (const event of parseSitemapStreamInternal(input, options, "urlset")) {
|
|
194
|
+
if (event._tag === "kind") {
|
|
195
|
+
if (event.kind !== "urlset")
|
|
196
|
+
throw new Error("XML does not contain a valid urlset element");
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (event._tag !== "sitemap")
|
|
200
|
+
yield event;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async function* parseSitemapIndexStream(input, options = {}) {
|
|
204
|
+
for await (const event of parseSitemapStreamInternal(input, options, "index")) {
|
|
205
|
+
if (event._tag === "kind") {
|
|
206
|
+
if (event.kind !== "index")
|
|
207
|
+
throw new Error("XML does not contain a valid sitemapindex element");
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (event._tag !== "url")
|
|
211
|
+
yield event;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
async function parseSitemapXml(xml) {
|
|
215
|
+
const urls = [];
|
|
216
|
+
const warnings = [];
|
|
217
|
+
for await (const event of parseSitemapXmlStream(xml)) {
|
|
218
|
+
if (event._tag === "url")
|
|
219
|
+
urls.push(event.url);
|
|
220
|
+
else
|
|
221
|
+
warnings.push(event.warning);
|
|
222
|
+
}
|
|
223
|
+
return { urls, warnings };
|
|
224
|
+
}
|
|
225
|
+
async function parseSitemapIndex(xml) {
|
|
226
|
+
const entries = [];
|
|
227
|
+
const warnings = [];
|
|
228
|
+
for await (const event of parseSitemapIndexStream(xml)) {
|
|
229
|
+
if (event._tag === "sitemap")
|
|
230
|
+
entries.push(event.sitemap);
|
|
231
|
+
else
|
|
232
|
+
warnings.push(event.warning);
|
|
233
|
+
}
|
|
234
|
+
return { entries, warnings };
|
|
235
|
+
}
|
|
236
|
+
function isSitemapIndex(xml) {
|
|
237
|
+
return xml.includes("<sitemapindex") || xml.includes("sitemapindex>");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export { isSitemapIndex, parseSitemapIndex, parseSitemapIndexStream, parseSitemapStream, parseSitemapXml, parseSitemapXmlStream };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/sitemap",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "8.3.
|
|
4
|
+
"version": "8.3.2",
|
|
5
5
|
"description": "Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@nuxtjs/robots": "^6.1.3",
|
|
81
81
|
"@vue/test-utils": "^2.4.11",
|
|
82
82
|
"better-sqlite3": "^13.0.1",
|
|
83
|
-
"bumpp": "^12.1.
|
|
83
|
+
"bumpp": "^12.1.1",
|
|
84
84
|
"eslint": "^10.8.0",
|
|
85
85
|
"eslint-plugin-harlanzw": "^0.17.1",
|
|
86
86
|
"happy-dom": "^20.11.1",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"vitest": "^4.1.10",
|
|
94
94
|
"vue-tsc": "^3.3.8",
|
|
95
95
|
"zod": "^4.4.3",
|
|
96
|
-
"@nuxtjs/sitemap": "8.3.
|
|
96
|
+
"@nuxtjs/sitemap": "8.3.2"
|
|
97
97
|
},
|
|
98
98
|
"scripts": {
|
|
99
99
|
"lint": "eslint .",
|