@nuxtjs/sitemap 7.4.0 → 7.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.mjs ADDED
@@ -0,0 +1,368 @@
1
+ import { XMLParser } from 'fast-xml-parser';
2
+ export { p as parseHtmlExtractSitemapMeta } from './shared/sitemap.DR3_6qqU.mjs';
3
+ import 'ufo';
4
+ import 'ultrahtml';
5
+
6
+ const parser = new XMLParser({
7
+ isArray: (tagName) => ["url", "image", "video", "link", "tag", "price"].includes(tagName),
8
+ removeNSPrefix: true,
9
+ parseAttributeValue: false,
10
+ ignoreAttributes: false,
11
+ attributeNamePrefix: "",
12
+ trimValues: true
13
+ });
14
+ function isValidString(value) {
15
+ return typeof value === "string" && value.trim().length > 0;
16
+ }
17
+ function parseNumber(value) {
18
+ if (typeof value === "number") return value;
19
+ if (typeof value === "string" && value.trim()) {
20
+ const num = Number.parseFloat(value.trim());
21
+ return Number.isNaN(num) ? void 0 : num;
22
+ }
23
+ return void 0;
24
+ }
25
+ function parseInteger(value) {
26
+ if (typeof value === "number") return Math.floor(value);
27
+ if (typeof value === "string" && value.trim()) {
28
+ const num = Number.parseInt(value.trim(), 10);
29
+ return Number.isNaN(num) ? void 0 : num;
30
+ }
31
+ return void 0;
32
+ }
33
+ function extractUrlFromParsedElement(urlElement, warnings) {
34
+ if (!isValidString(urlElement.loc)) {
35
+ warnings.push({
36
+ type: "validation",
37
+ message: "URL entry missing required loc element",
38
+ context: { url: String(urlElement.loc || "undefined") }
39
+ });
40
+ return null;
41
+ }
42
+ const urlObj = { loc: urlElement.loc };
43
+ if (isValidString(urlElement.lastmod)) {
44
+ urlObj.lastmod = urlElement.lastmod;
45
+ }
46
+ if (isValidString(urlElement.changefreq)) {
47
+ const validFreqs = ["always", "hourly", "daily", "weekly", "monthly", "yearly", "never"];
48
+ if (validFreqs.includes(urlElement.changefreq)) {
49
+ urlObj.changefreq = urlElement.changefreq;
50
+ } else {
51
+ warnings.push({
52
+ type: "validation",
53
+ message: "Invalid changefreq value",
54
+ context: { url: urlElement.loc, field: "changefreq", value: urlElement.changefreq }
55
+ });
56
+ }
57
+ }
58
+ const priority = parseNumber(urlElement.priority);
59
+ if (priority !== void 0 && !Number.isNaN(priority)) {
60
+ if (priority < 0 || priority > 1) {
61
+ warnings.push({
62
+ type: "validation",
63
+ message: "Priority value should be between 0.0 and 1.0, clamping to valid range",
64
+ context: { url: urlElement.loc, field: "priority", value: priority }
65
+ });
66
+ }
67
+ urlObj.priority = Math.max(0, Math.min(1, priority));
68
+ } else if (urlElement.priority !== void 0) {
69
+ warnings.push({
70
+ type: "validation",
71
+ message: "Invalid priority value",
72
+ context: { url: urlElement.loc, field: "priority", value: urlElement.priority }
73
+ });
74
+ }
75
+ if (urlElement.image) {
76
+ const images = Array.isArray(urlElement.image) ? urlElement.image : [urlElement.image];
77
+ const validImages = images.map((img) => {
78
+ if (isValidString(img.loc)) {
79
+ return { loc: img.loc };
80
+ } else {
81
+ warnings.push({
82
+ type: "validation",
83
+ message: "Image missing required loc element",
84
+ context: { url: urlElement.loc, field: "image.loc" }
85
+ });
86
+ return null;
87
+ }
88
+ }).filter((img) => img !== null);
89
+ if (validImages.length > 0) {
90
+ urlObj.images = validImages;
91
+ }
92
+ }
93
+ if (urlElement.video) {
94
+ const videos = Array.isArray(urlElement.video) ? urlElement.video : [urlElement.video];
95
+ const validVideos = videos.map((video) => {
96
+ const missingFields = [];
97
+ if (!isValidString(video.title)) missingFields.push("title");
98
+ if (!isValidString(video.thumbnail_loc)) missingFields.push("thumbnail_loc");
99
+ if (!isValidString(video.description)) missingFields.push("description");
100
+ if (!isValidString(video.content_loc)) missingFields.push("content_loc");
101
+ if (missingFields.length > 0) {
102
+ warnings.push({
103
+ type: "validation",
104
+ message: `Video missing required fields: ${missingFields.join(", ")}`,
105
+ context: { url: urlElement.loc, field: "video" }
106
+ });
107
+ return null;
108
+ }
109
+ const videoObj = {
110
+ title: video.title,
111
+ thumbnail_loc: video.thumbnail_loc,
112
+ description: video.description,
113
+ content_loc: video.content_loc
114
+ };
115
+ if (isValidString(video.player_loc)) {
116
+ videoObj.player_loc = video.player_loc;
117
+ }
118
+ const duration = parseInteger(video.duration);
119
+ if (duration !== void 0) {
120
+ videoObj.duration = duration;
121
+ } else if (video.duration !== void 0) {
122
+ warnings.push({
123
+ type: "validation",
124
+ message: "Invalid video duration value",
125
+ context: { url: urlElement.loc, field: "video.duration", value: video.duration }
126
+ });
127
+ }
128
+ if (isValidString(video.expiration_date)) {
129
+ videoObj.expiration_date = video.expiration_date;
130
+ }
131
+ const rating = parseNumber(video.rating);
132
+ if (rating !== void 0) {
133
+ if (rating < 0 || rating > 5) {
134
+ warnings.push({
135
+ type: "validation",
136
+ message: "Video rating should be between 0.0 and 5.0",
137
+ context: { url: urlElement.loc, field: "video.rating", value: rating }
138
+ });
139
+ }
140
+ videoObj.rating = rating;
141
+ } else if (video.rating !== void 0) {
142
+ warnings.push({
143
+ type: "validation",
144
+ message: "Invalid video rating value",
145
+ context: { url: urlElement.loc, field: "video.rating", value: video.rating }
146
+ });
147
+ }
148
+ const viewCount = parseInteger(video.view_count);
149
+ if (viewCount !== void 0) {
150
+ videoObj.view_count = viewCount;
151
+ } else if (video.view_count !== void 0) {
152
+ warnings.push({
153
+ type: "validation",
154
+ message: "Invalid video view_count value",
155
+ context: { url: urlElement.loc, field: "video.view_count", value: video.view_count }
156
+ });
157
+ }
158
+ if (isValidString(video.publication_date)) {
159
+ videoObj.publication_date = video.publication_date;
160
+ }
161
+ if (isValidString(video.family_friendly)) {
162
+ const validValues = ["yes", "no"];
163
+ if (validValues.includes(video.family_friendly)) {
164
+ videoObj.family_friendly = video.family_friendly;
165
+ } else {
166
+ warnings.push({
167
+ type: "validation",
168
+ message: 'Invalid video family_friendly value, should be "yes" or "no"',
169
+ context: { url: urlElement.loc, field: "video.family_friendly", value: video.family_friendly }
170
+ });
171
+ }
172
+ }
173
+ if (isValidString(video.requires_subscription)) {
174
+ const validValues = ["yes", "no"];
175
+ if (validValues.includes(video.requires_subscription)) {
176
+ videoObj.requires_subscription = video.requires_subscription;
177
+ } else {
178
+ warnings.push({
179
+ type: "validation",
180
+ message: 'Invalid video requires_subscription value, should be "yes" or "no"',
181
+ context: { url: urlElement.loc, field: "video.requires_subscription", value: video.requires_subscription }
182
+ });
183
+ }
184
+ }
185
+ if (isValidString(video.live)) {
186
+ const validValues = ["yes", "no"];
187
+ if (validValues.includes(video.live)) {
188
+ videoObj.live = video.live;
189
+ } else {
190
+ warnings.push({
191
+ type: "validation",
192
+ message: 'Invalid video live value, should be "yes" or "no"',
193
+ context: { url: urlElement.loc, field: "video.live", value: video.live }
194
+ });
195
+ }
196
+ }
197
+ if (video.restriction && typeof video.restriction === "object") {
198
+ const restriction = video.restriction;
199
+ if (isValidString(restriction.relationship) && isValidString(restriction["#text"])) {
200
+ const validRelationships = ["allow", "deny"];
201
+ if (validRelationships.includes(restriction.relationship)) {
202
+ videoObj.restriction = {
203
+ relationship: restriction.relationship,
204
+ restriction: restriction["#text"]
205
+ };
206
+ } else {
207
+ warnings.push({
208
+ type: "validation",
209
+ message: 'Invalid video restriction relationship, should be "allow" or "deny"',
210
+ context: { url: urlElement.loc, field: "video.restriction.relationship", value: restriction.relationship }
211
+ });
212
+ }
213
+ }
214
+ }
215
+ if (video.platform && typeof video.platform === "object") {
216
+ const platform = video.platform;
217
+ if (isValidString(platform.relationship) && isValidString(platform["#text"])) {
218
+ const validRelationships = ["allow", "deny"];
219
+ if (validRelationships.includes(platform.relationship)) {
220
+ videoObj.platform = {
221
+ relationship: platform.relationship,
222
+ platform: platform["#text"]
223
+ };
224
+ } else {
225
+ warnings.push({
226
+ type: "validation",
227
+ message: 'Invalid video platform relationship, should be "allow" or "deny"',
228
+ context: { url: urlElement.loc, field: "video.platform.relationship", value: platform.relationship }
229
+ });
230
+ }
231
+ }
232
+ }
233
+ if (video.price) {
234
+ const prices = Array.isArray(video.price) ? video.price : [video.price];
235
+ const validPrices = prices.map((price) => {
236
+ const priceValue = price["#text"];
237
+ if (priceValue == null || typeof priceValue !== "string" && typeof priceValue !== "number") {
238
+ warnings.push({
239
+ type: "validation",
240
+ message: "Video price missing value",
241
+ context: { url: urlElement.loc, field: "video.price" }
242
+ });
243
+ return null;
244
+ }
245
+ const validTypes = ["rent", "purchase", "package", "subscription"];
246
+ if (price.type && !validTypes.includes(price.type)) {
247
+ warnings.push({
248
+ type: "validation",
249
+ message: `Invalid video price type "${price.type}", should be one of: ${validTypes.join(", ")}`,
250
+ context: { url: urlElement.loc, field: "video.price.type", value: price.type }
251
+ });
252
+ }
253
+ return {
254
+ price: String(priceValue),
255
+ currency: price.currency,
256
+ type: price.type
257
+ };
258
+ }).filter((p) => p !== null);
259
+ if (validPrices.length > 0) {
260
+ videoObj.price = validPrices;
261
+ }
262
+ }
263
+ if (video.uploader && typeof video.uploader === "object") {
264
+ const uploader = video.uploader;
265
+ if (isValidString(uploader.info) && isValidString(uploader["#text"])) {
266
+ videoObj.uploader = {
267
+ uploader: uploader["#text"],
268
+ info: uploader.info
269
+ };
270
+ } else {
271
+ warnings.push({
272
+ type: "validation",
273
+ message: "Video uploader missing required info or name",
274
+ context: { url: urlElement.loc, field: "video.uploader" }
275
+ });
276
+ }
277
+ }
278
+ if (video.tag) {
279
+ const tags = Array.isArray(video.tag) ? video.tag : [video.tag];
280
+ const validTags = tags.filter(isValidString);
281
+ if (validTags.length > 0) {
282
+ videoObj.tag = validTags;
283
+ }
284
+ }
285
+ return videoObj;
286
+ }).filter((video) => video !== null);
287
+ if (validVideos.length > 0) {
288
+ urlObj.videos = validVideos;
289
+ }
290
+ }
291
+ if (urlElement.link) {
292
+ const links = Array.isArray(urlElement.link) ? urlElement.link : [urlElement.link];
293
+ const alternatives = links.map((link) => {
294
+ if (link.rel === "alternate" && isValidString(link.hreflang) && isValidString(link.href)) {
295
+ return {
296
+ hreflang: link.hreflang,
297
+ href: link.href
298
+ };
299
+ } else {
300
+ warnings.push({
301
+ type: "validation",
302
+ message: 'Alternative link missing required rel="alternate", hreflang, or href',
303
+ context: { url: urlElement.loc, field: "link" }
304
+ });
305
+ return null;
306
+ }
307
+ }).filter((alt) => alt !== null);
308
+ if (alternatives.length > 0) {
309
+ urlObj.alternatives = alternatives;
310
+ }
311
+ }
312
+ if (urlElement.news && typeof urlElement.news === "object") {
313
+ const news = urlElement.news;
314
+ if (isValidString(news.title) && isValidString(news.publication_date) && news.publication && isValidString(news.publication.name) && isValidString(news.publication.language)) {
315
+ urlObj.news = {
316
+ title: news.title,
317
+ publication_date: news.publication_date,
318
+ publication: {
319
+ name: news.publication.name,
320
+ language: news.publication.language
321
+ }
322
+ };
323
+ } else {
324
+ warnings.push({
325
+ type: "validation",
326
+ message: "News entry missing required fields (title, publication_date, publication.name, publication.language)",
327
+ context: { url: urlElement.loc, field: "news" }
328
+ });
329
+ }
330
+ }
331
+ const filteredUrlObj = Object.fromEntries(
332
+ Object.entries(urlObj).filter(
333
+ ([_, value]) => value != null && (!Array.isArray(value) || value.length > 0)
334
+ )
335
+ );
336
+ return filteredUrlObj;
337
+ }
338
+ function parseSitemapXml(xml) {
339
+ const warnings = [];
340
+ if (!xml) {
341
+ throw new Error("Empty XML input provided");
342
+ }
343
+ try {
344
+ const parsed = parser.parse(xml);
345
+ if (!parsed?.urlset) {
346
+ throw new Error("XML does not contain a valid urlset element");
347
+ }
348
+ if (!parsed.urlset.url) {
349
+ throw new Error("Sitemap contains no URL entries");
350
+ }
351
+ const urls = Array.isArray(parsed.urlset.url) ? parsed.urlset.url : [parsed.urlset.url];
352
+ const validUrls = urls.map((url) => extractUrlFromParsedElement(url, warnings)).filter((url) => url !== null);
353
+ if (validUrls.length === 0 && urls.length > 0) {
354
+ warnings.push({
355
+ type: "validation",
356
+ message: "No valid URLs found in sitemap after validation"
357
+ });
358
+ }
359
+ return { urls: validUrls, warnings };
360
+ } catch (error) {
361
+ if (error instanceof Error && (error.message === "Empty XML input provided" || error.message === "XML does not contain a valid urlset element" || error.message === "Sitemap contains no URL entries")) {
362
+ throw error;
363
+ }
364
+ throw new Error(`Failed to parse XML: ${error instanceof Error ? error.message : String(error)}`);
365
+ }
366
+ }
367
+
368
+ export { parseSitemapXml };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxtjs/sitemap",
3
3
  "type": "module",
4
- "version": "7.4.0",
4
+ "version": "7.4.1",
5
5
  "description": "Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -26,7 +26,8 @@
26
26
  "types": "./dist/types.d.mts",
27
27
  "import": "./dist/module.mjs"
28
28
  },
29
- "./content": "./dist/content.mjs"
29
+ "./content": "./dist/content.mjs",
30
+ "./utils": "./dist/utils.mjs"
30
31
  },
31
32
  "main": "./dist/module.mjs",
32
33
  "files": [
@@ -40,6 +41,9 @@
40
41
  ],
41
42
  "content": [
42
43
  "./dist/content.d.mts"
44
+ ],
45
+ "utils": [
46
+ "./dist/utils.d.mts"
43
47
  ]
44
48
  }
45
49
  },
@@ -48,15 +52,18 @@
48
52
  "@nuxt/kit": "^3.17.5",
49
53
  "chalk": "^5.4.1",
50
54
  "defu": "^6.1.4",
55
+ "fast-xml-parser": "^5.2.5",
51
56
  "h3-compression": "^0.3.2",
52
- "nuxt-site-config": "^3.2.0",
57
+ "nuxt-site-config": "^3.2.1",
53
58
  "ofetch": "^1.4.1",
54
59
  "pathe": "^2.0.3",
55
60
  "pkg-types": "^2.1.0",
56
61
  "radix3": "^1.1.2",
57
62
  "semver": "^7.7.2",
58
63
  "sirv": "^3.0.1",
59
- "ufo": "^1.6.1"
64
+ "std-env": "^3.9.0",
65
+ "ufo": "^1.6.1",
66
+ "ultrahtml": "^1.6.0"
60
67
  },
61
68
  "devDependencies": {
62
69
  "@arethetypeswrong/cli": "^0.18.2",
@@ -68,7 +75,7 @@
68
75
  "@nuxtjs/i18n": "^9.5.5",
69
76
  "@nuxtjs/robots": "^5.2.10",
70
77
  "better-sqlite3": "^11.10.0",
71
- "bumpp": "^10.1.1",
78
+ "bumpp": "^10.2.0",
72
79
  "eslint": "^9.29.0",
73
80
  "eslint-plugin-n": "^17.20.0",
74
81
  "execa": "^9.6.0",
@@ -76,7 +83,7 @@
76
83
  "nuxt": "^3.17.5",
77
84
  "nuxt-i18n-micro": "^1.87.0",
78
85
  "typescript": "^5.8.3",
79
- "vitest": "^3.2.3",
86
+ "vitest": "^3.2.4",
80
87
  "vue-tsc": "^2.2.10"
81
88
  },
82
89
  "scripts": {
@@ -90,7 +97,8 @@
90
97
  "dev:build": "nuxi build playground",
91
98
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
92
99
  "release": "pnpm build && bumpp && pnpm -r publish",
93
- "test": "vitest && pnpm run test:attw",
100
+ "test": "vitest run && pnpm run test:attw",
101
+ "test:unit": "vitest --project=unit",
94
102
  "test:attw": "attw --pack",
95
103
  "typecheck": "vue-tsc --noEmit"
96
104
  }
@@ -1 +0,0 @@
1
- {"id":"048e1f4c-a575-4a94-bbab-d777afe4c585","timestamp":1749875586228,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
package/dist/content.cjs DELETED
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- const content = require('@nuxt/content');
4
-
5
- const schema = content.z.object({
6
- sitemap: content.z.object({
7
- loc: content.z.string().optional(),
8
- lastmod: content.z.date().optional(),
9
- changefreq: content.z.union([content.z.literal("always"), content.z.literal("hourly"), content.z.literal("daily"), content.z.literal("weekly"), content.z.literal("monthly"), content.z.literal("yearly"), content.z.literal("never")]).optional(),
10
- priority: content.z.number().optional(),
11
- images: content.z.array(content.z.object({
12
- loc: content.z.string(),
13
- caption: content.z.string().optional(),
14
- geo_location: content.z.string().optional(),
15
- title: content.z.string().optional(),
16
- license: content.z.string().optional()
17
- })).optional(),
18
- videos: content.z.array(content.z.object({
19
- content_loc: content.z.string(),
20
- player_loc: content.z.string().optional(),
21
- duration: content.z.string().optional(),
22
- expiration_date: content.z.date().optional(),
23
- rating: content.z.number().optional(),
24
- view_count: content.z.number().optional(),
25
- publication_date: content.z.date().optional(),
26
- family_friendly: content.z.boolean().optional(),
27
- tag: content.z.string().optional(),
28
- category: content.z.string().optional(),
29
- restriction: content.z.object({
30
- relationship: content.z.literal("allow").optional(),
31
- value: content.z.string().optional()
32
- }).optional(),
33
- gallery_loc: content.z.string().optional(),
34
- price: content.z.string().optional(),
35
- requires_subscription: content.z.boolean().optional(),
36
- uploader: content.z.string().optional()
37
- })).optional()
38
- }).optional()
39
- });
40
- function asSitemapCollection(collection) {
41
- if (collection.type === "page") {
42
- collection.schema = collection.schema ? schema.extend(collection.schema.shape) : schema;
43
- }
44
- return collection;
45
- }
46
-
47
- exports.asSitemapCollection = asSitemapCollection;
48
- exports.schema = schema;