@nuxtjs/sitemap 7.3.1 → 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.
Files changed (47) hide show
  1. package/dist/client/200.html +7 -8
  2. package/dist/client/404.html +7 -8
  3. package/dist/client/_nuxt/ChEizYIG.js +172 -0
  4. package/dist/client/_nuxt/{CT3BV8Rj.js → SQMF8ibg.js} +1 -1
  5. package/dist/client/_nuxt/builds/latest.json +1 -1
  6. package/dist/client/_nuxt/builds/meta/096c9e6a-a9a8-483d-bd1d-fed5634b0d08.json +1 -0
  7. package/dist/client/_nuxt/{5vafBU9X.js → cqJZcoo0.js} +1 -1
  8. package/dist/client/_nuxt/error-404.DljSaiyF.css +1 -0
  9. package/dist/client/_nuxt/error-500.DbX9fggi.css +1 -0
  10. package/dist/client/index.html +7 -8
  11. package/dist/module.d.ts +1 -1
  12. package/dist/module.json +1 -1
  13. package/dist/module.mjs +32 -138
  14. package/dist/runtime/server/content-compat.d.ts +1 -0
  15. package/dist/runtime/server/content-compat.js +2 -0
  16. package/dist/runtime/server/routes/__sitemap__/nuxt-content-urls-v3.d.ts +1 -1
  17. package/dist/runtime/server/routes/__sitemap__/nuxt-content-urls-v3.js +4 -2
  18. package/dist/runtime/server/routes/sitemap.xsl.js +37 -13
  19. package/dist/runtime/server/routes/sitemap_index.xml.js +6 -2
  20. package/dist/runtime/server/sitemap/builder/sitemap-index.d.ts +11 -2
  21. package/dist/runtime/server/sitemap/builder/sitemap-index.js +23 -5
  22. package/dist/runtime/server/sitemap/builder/sitemap.d.ts +7 -1
  23. package/dist/runtime/server/sitemap/builder/sitemap.js +10 -5
  24. package/dist/runtime/server/sitemap/builder/xml.d.ts +4 -1
  25. package/dist/runtime/server/sitemap/builder/xml.js +13 -4
  26. package/dist/runtime/server/sitemap/nitro.js +7 -3
  27. package/dist/runtime/server/sitemap/urlset/normalise.js +4 -3
  28. package/dist/runtime/server/sitemap/urlset/sources.js +65 -19
  29. package/dist/runtime/server/utils.d.ts +1 -0
  30. package/dist/runtime/server/utils.js +3 -0
  31. package/dist/runtime/types.d.ts +2 -0
  32. package/dist/shared/sitemap.DR3_6qqU.mjs +212 -0
  33. package/dist/utils.d.mts +28 -0
  34. package/dist/utils.d.ts +28 -0
  35. package/dist/utils.mjs +368 -0
  36. package/package.json +24 -15
  37. package/dist/client/_nuxt/BIHI7g3E.js +0 -1
  38. package/dist/client/_nuxt/Bn78IMkz.js +0 -172
  39. package/dist/client/_nuxt/builds/meta/5ecca6e1-2b8a-4fc5-a128-35cbc27bf6d7.json +0 -1
  40. package/dist/client/_nuxt/error-404.D_zhMyJm.css +0 -1
  41. package/dist/client/_nuxt/error-500.rdOYVbxo.css +0 -1
  42. package/dist/content.cjs +0 -48
  43. package/dist/content.d.cts +0 -232
  44. package/dist/module.cjs +0 -1324
  45. package/dist/module.d.cts +0 -10
  46. package/dist/runtime/server/sitemap/utils/extractSitemapXML.d.ts +0 -2
  47. package/dist/runtime/server/sitemap/utils/extractSitemapXML.js +0 -75
package/dist/module.cjs DELETED
@@ -1,1324 +0,0 @@
1
- 'use strict';
2
-
3
- const kit = require('@nuxt/kit');
4
- const ufo = require('ufo');
5
- const kit$1 = require('nuxt-site-config/kit');
6
- const defu = require('defu');
7
- const pkgTypes = require('pkg-types');
8
- const pathe = require('pathe');
9
- const node_fs = require('node:fs');
10
- const utilsPure_js = require('../dist/runtime/utils-pure.js');
11
- const stdEnv = require('std-env');
12
- const promises = require('node:fs/promises');
13
- const node_path = require('node:path');
14
- const chalk = require('chalk');
15
- const normalise_js = require('../dist/runtime/server/sitemap/urlset/normalise.js');
16
-
17
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
18
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
19
-
20
- const chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
21
-
22
- async function resolveUrls(urls, ctx) {
23
- if (typeof urls === "function")
24
- urls = urls();
25
- urls = await urls;
26
- try {
27
- urls = JSON.parse(JSON.stringify(urls));
28
- } catch (e) {
29
- ctx.logger.warn(`Failed to serialize ${typeof urls} \`${ctx.path}\`, please make sure that the urls resolve as a valid array without circular dependencies.`);
30
- ctx.logger.error(e);
31
- return [];
32
- }
33
- return urls;
34
- }
35
- function deepForEachPage(pages, callback, opts, fullpath = null, depth = 0) {
36
- pages.forEach((page) => {
37
- let currentPath;
38
- if (page.path.startsWith("/")) {
39
- currentPath = page.path;
40
- } else {
41
- currentPath = page.path === "" ? fullpath : `${fullpath.replace(/\/$/, "")}/${page.path}`;
42
- }
43
- let didCallback = false;
44
- if (opts.isI18nMicro) {
45
- const localePattern = /\/:locale\(([^)]+)\)/;
46
- const match = localePattern.exec(currentPath || "");
47
- if (match) {
48
- const locales = match[1].split("|");
49
- locales.forEach((locale) => {
50
- const subPage = { ...page };
51
- const localizedPath = (currentPath || "").replace(localePattern, `/${locale}`);
52
- subPage.name += opts.routesNameSeparator + locale;
53
- subPage.path = localizedPath;
54
- callback(subPage, localizedPath || "", depth);
55
- didCallback = true;
56
- });
57
- }
58
- }
59
- if (!didCallback) {
60
- callback(page, currentPath || "", depth);
61
- }
62
- if (page.children) {
63
- deepForEachPage(page.children, callback, opts, currentPath, depth + 1);
64
- }
65
- });
66
- }
67
- function convertNuxtPagesToSitemapEntries(pages, config) {
68
- const pathFilter = utilsPure_js.createPathFilter(config.filter);
69
- const routesNameSeparator = config.routesNameSeparator || "___";
70
- let flattenedPages = [];
71
- deepForEachPage(
72
- pages,
73
- (page, loc, depth) => {
74
- flattenedPages.push({ page, loc, depth });
75
- },
76
- {
77
- ...config,
78
- routesNameSeparator: config.routesNameSeparator || "___"
79
- }
80
- );
81
- flattenedPages = flattenedPages.filter((page) => !page.loc.includes(":")).filter((page, idx, arr) => {
82
- return !arr.find((p) => {
83
- return p.loc === page.loc && p.depth > page.depth;
84
- });
85
- }).map((p) => {
86
- delete p.depth;
87
- return p;
88
- });
89
- if (config.strategy === "prefix_and_default") {
90
- flattenedPages = flattenedPages.filter((p) => {
91
- if (p.page?.name) {
92
- const [, locale] = p.page.name.split(routesNameSeparator);
93
- return locale !== config.defaultLocale || p.page.name.endsWith("__default");
94
- }
95
- return true;
96
- });
97
- }
98
- const pagesWithMeta = flattenedPages.map((p) => {
99
- if (config.autoLastmod && p.page.file) {
100
- try {
101
- const stats = node_fs.statSync(p.page.file);
102
- if (stats?.mtime)
103
- p.lastmod = stats.mtime;
104
- } catch {
105
- }
106
- }
107
- if (p.page?.meta?.sitemap) {
108
- p = defu.defu(p.page.meta.sitemap, p);
109
- }
110
- return p;
111
- });
112
- const localeGroups = {};
113
- pagesWithMeta.reduce((acc, e) => {
114
- if (e.page.name?.includes(routesNameSeparator)) {
115
- const [name, locale] = e.page.name.split(routesNameSeparator);
116
- if (!acc[name])
117
- acc[name] = [];
118
- const { _sitemap } = config.normalisedLocales.find((l) => l.code === locale) || { _sitemap: locale };
119
- acc[name].push({ ...e, _sitemap: config.isI18nMapped ? _sitemap : void 0, locale });
120
- } else {
121
- acc.default = acc.default || [];
122
- acc.default.push(e);
123
- }
124
- return acc;
125
- }, localeGroups);
126
- return Object.entries(localeGroups).map(([locale, entries]) => {
127
- if (locale === "default") {
128
- return entries.map((e) => {
129
- const [name] = (e.page?.name || "").split(routesNameSeparator);
130
- if (localeGroups[name]?.some((a) => a.locale === config.defaultLocale))
131
- return false;
132
- const defaultLocale = config.normalisedLocales.find((l) => l.code === config.defaultLocale);
133
- if (defaultLocale && config.isI18nMapped)
134
- e._sitemap = defaultLocale._sitemap;
135
- delete e.page;
136
- delete e.locale;
137
- return { ...e };
138
- }).filter(Boolean);
139
- }
140
- return entries.map((entry) => {
141
- const alternatives = entries.map((entry2) => {
142
- const locale2 = config.normalisedLocales.find((l) => l.code === entry2.locale);
143
- if (!pathFilter(entry2.loc))
144
- return false;
145
- const href = locale2?.domain ? ufo.withHttps(ufo.withBase(entry2.loc, locale2?.domain)) : entry2.loc;
146
- return {
147
- hreflang: locale2?._hreflang,
148
- href
149
- };
150
- }).filter(Boolean);
151
- const xDefault = entries.find((a) => a.locale === config.defaultLocale);
152
- if (xDefault && alternatives.length && pathFilter(xDefault.loc)) {
153
- const locale2 = config.normalisedLocales.find((l) => l.code === xDefault.locale);
154
- const href = locale2?.domain ? ufo.withHttps(ufo.withBase(xDefault.loc, locale2?.domain)) : xDefault.loc;
155
- alternatives.push({
156
- hreflang: "x-default",
157
- href
158
- });
159
- }
160
- const e = { ...entry };
161
- if (config.isI18nMapped) {
162
- const { _sitemap } = config.normalisedLocales.find((l) => l.code === entry.locale) || { _sitemap: locale };
163
- e._sitemap = _sitemap;
164
- }
165
- delete e.page;
166
- delete e.locale;
167
- return {
168
- ...e,
169
- alternatives
170
- };
171
- });
172
- }).filter(Boolean).flat();
173
- }
174
- function generateExtraRoutesFromNuxtConfig(nuxt = kit.useNuxt()) {
175
- const filterForValidPage = (p) => p && !pathe.extname(p) && !p.startsWith("/api/") && !p.startsWith("/_");
176
- const routeRules = Object.entries(nuxt.options.routeRules || {}).filter(([k, v]) => {
177
- if (k.includes("*") || k.includes(".") || k.includes(":"))
178
- return false;
179
- if (typeof v.robots === "boolean" && !v.robots)
180
- return false;
181
- return !v.redirect;
182
- }).map(([k]) => k).filter(filterForValidPage);
183
- const prerenderUrls = (nuxt.options.nitro.prerender?.routes || []).filter(filterForValidPage);
184
- return { routeRules, prerenderUrls };
185
- }
186
-
187
- async function getNuxtModuleOptions(module, nuxt = kit.useNuxt()) {
188
- const moduleMeta = (typeof module === "string" ? { name: module } : await module.getMeta?.()) || {};
189
- const { nuxtModule } = await kit.loadNuxtModuleInstance(module, nuxt);
190
- let moduleEntry;
191
- for (const m of nuxt.options.modules) {
192
- if (Array.isArray(m) && m.length >= 2) {
193
- const _module = m[0];
194
- const _moduleEntryName = typeof _module === "string" ? _module : (await _module.getMeta?.())?.name || "";
195
- if (_moduleEntryName === moduleMeta.name)
196
- moduleEntry = m;
197
- }
198
- }
199
- let inlineOptions = {};
200
- if (moduleEntry)
201
- inlineOptions = moduleEntry[1];
202
- if (nuxtModule.getOptions)
203
- return nuxtModule.getOptions(inlineOptions, nuxt);
204
- return inlineOptions;
205
- }
206
- function extendTypes(module, template) {
207
- const nuxt = kit.useNuxt();
208
- const { resolve } = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
209
- const fileName = `${module.replace("/", "-")}.d.ts`;
210
- kit.addTemplate({
211
- filename: `module/${fileName}`,
212
- getContents: async () => {
213
- const typesPath = pathe.relative(resolve(nuxt.options.rootDir, nuxt.options.buildDir, "module"), resolve("../runtime/types"));
214
- const s = await template({ typesPath });
215
- return `// Generated by ${module}
216
- ${s}
217
- export {}
218
- `;
219
- }
220
- });
221
- nuxt.hooks.hook("prepare:types", ({ references }) => {
222
- references.push({ path: resolve(nuxt.options.buildDir, `module/${fileName}`) });
223
- });
224
- nuxt.hooks.hook("nitro:config", (config) => {
225
- config.typescript = config.typescript || {};
226
- config.typescript.tsConfig = config.typescript.tsConfig || {};
227
- config.typescript.tsConfig.include = config.typescript.tsConfig.include || [];
228
- config.typescript.tsConfig.include.push(`./module/${fileName}`);
229
- });
230
- }
231
- function createPagesPromise(nuxt = kit.useNuxt()) {
232
- return new Promise((resolve) => {
233
- nuxt.hooks.hook("modules:done", () => {
234
- if (typeof nuxt.options.pages === "boolean" && nuxt.options.pages === false || typeof nuxt.options.pages === "object" && !nuxt.options.pages.enabled) {
235
- return resolve([]);
236
- }
237
- kit.extendPages(resolve);
238
- });
239
- });
240
- }
241
- function createNitroPromise(nuxt = kit.useNuxt()) {
242
- return new Promise((resolve) => {
243
- nuxt.hooks.hook("nitro:init", (nitro) => {
244
- resolve(nitro);
245
- });
246
- });
247
- }
248
- const autodetectableProviders = {
249
- azure_static: "azure",
250
- cloudflare_pages: "cloudflare-pages",
251
- netlify: "netlify",
252
- stormkit: "stormkit",
253
- vercel: "vercel",
254
- cleavr: "cleavr",
255
- stackblitz: "stackblitz"
256
- };
257
- const autodetectableStaticProviders = {
258
- netlify: "netlify-static",
259
- vercel: "vercel-static"
260
- };
261
- function detectTarget(options = {}) {
262
- return options?.static ? autodetectableStaticProviders[stdEnv.provider] : autodetectableProviders[stdEnv.provider];
263
- }
264
- function resolveNitroPreset(nitroConfig) {
265
- nitroConfig = nitroConfig || kit.tryUseNuxt()?.options?.nitro;
266
- if (stdEnv.provider === "stackblitz")
267
- return "stackblitz";
268
- let preset;
269
- if (nitroConfig && nitroConfig?.preset)
270
- preset = nitroConfig.preset;
271
- if (!preset)
272
- preset = stdEnv.env.NITRO_PRESET || stdEnv.env.SERVER_PRESET || detectTarget() || "node-server";
273
- return preset.replace("_", "-");
274
- }
275
-
276
- const videoRegex = /<video[^>]*>([\s\S]*?)<\/video>/g;
277
- const videoSrcRegex = /<video[^>]*\ssrc="([^"]+)"/;
278
- const videoPosterRegex = /<video[^>]*\sposter="([^"]+)"/;
279
- const videoTitleRegex = /<video[^>]*\sdata-title="([^"]+)"/;
280
- const videoDescriptionRegex = /<video[^>]*\sdata-description="([^"]+)"/;
281
- const videoPlayerLocRegex = /<video[^>]*\sdata-player-loc="([^"]+)"/;
282
- const videoDurationRegex = /<video[^>]*\sdata-duration="([^"]+)"/;
283
- const videoExpirationDateRegex = /<video[^>]*\sdata-expiration-date="([^"]+)"/;
284
- const videoRatingRegex = /<video[^>]*\sdata-rating="([^"]+)"/;
285
- const videoViewCountRegex = /<video[^>]*\sdata-view-count="([^"]+)"/;
286
- const videoPublicationDateRegex = /<video[^>]*\sdata-publication-date="([^"]+)"/;
287
- const videoFamilyFriendlyRegex = /<video[^>]*\sdata-family-friendly="([^"]+)"/;
288
- const videoRequiresSubscriptionRegex = /<video[^>]*\sdata-requires-subscription="([^"]+)"/;
289
- const videoLiveRegex = /<video[^>]*\sdata-live="([^"]+)"/;
290
- const videoTagRegex = /<video[^>]*\sdata-tag="([^"]+)"/;
291
- const sourceRegex = /<source[^>]*\ssrc="([^"]+)"/g;
292
- function extractSitemapMetaFromHtml(html, options) {
293
- options = options || { images: true, videos: true, lastmod: true, alternatives: true };
294
- const payload = {};
295
- const resolveUrl = options?.resolveUrl || ((s) => s);
296
- const mainRegex = /<main[^>]*>([\s\S]*?)<\/main>/;
297
- const mainMatch = mainRegex.exec(html);
298
- if (options?.images) {
299
- const images = /* @__PURE__ */ new Set();
300
- if (mainMatch?.[1] && mainMatch[1].includes("<img")) {
301
- const imgRegex = /<img\s+(?:[^>]*?\s)?src=["']((?!data:|blob:|file:)[^"']+?)["'][^>]*>/gi;
302
- let match;
303
- while ((match = imgRegex.exec(mainMatch[1])) !== null) {
304
- if (match.index === imgRegex.lastIndex)
305
- imgRegex.lastIndex++;
306
- const url = resolveUrl(match[1]);
307
- images.add(url);
308
- }
309
- }
310
- if (images.size > 0)
311
- payload.images = [...images].map((i) => ({ loc: i }));
312
- }
313
- if (options?.videos) {
314
- const videos = [];
315
- if (mainMatch?.[1] && mainMatch[1].includes("<video")) {
316
- let videoMatch;
317
- while ((videoMatch = videoRegex.exec(mainMatch[1])) !== null) {
318
- const videoContent = videoMatch[1];
319
- const videoTag = videoMatch[0];
320
- const content_loc = (videoSrcRegex.exec(videoTag) || [])[1] || "";
321
- const thumbnail_loc = (videoPosterRegex.exec(videoTag) || [])[1] || "";
322
- const title = (videoTitleRegex.exec(videoTag) || [])[1] || "";
323
- const description = (videoDescriptionRegex.exec(videoTag) || [])[1] || "";
324
- const videoObj = {
325
- content_loc,
326
- thumbnail_loc,
327
- title,
328
- description
329
- };
330
- const player_loc = (videoPlayerLocRegex.exec(videoTag) || [])[1];
331
- if (player_loc) videoObj.player_loc = player_loc;
332
- const duration = (videoDurationRegex.exec(videoTag) || [])[1];
333
- if (duration) videoObj.duration = Number.parseInt(duration, 10);
334
- const expiration_date = (videoExpirationDateRegex.exec(videoTag) || [])[1];
335
- if (expiration_date) videoObj.expiration_date = expiration_date;
336
- const rating = (videoRatingRegex.exec(videoTag) || [])[1];
337
- if (rating) videoObj.rating = Number.parseFloat(rating);
338
- const view_count = (videoViewCountRegex.exec(videoTag) || [])[1];
339
- if (view_count) videoObj.view_count = Number.parseInt(view_count, 10);
340
- const publication_date = (videoPublicationDateRegex.exec(videoTag) || [])[1];
341
- if (publication_date) videoObj.publication_date = publication_date;
342
- const family_friendly = (videoFamilyFriendlyRegex.exec(videoTag) || [])[1];
343
- if (family_friendly) videoObj.family_friendly = family_friendly;
344
- const requires_subscription = (videoRequiresSubscriptionRegex.exec(videoTag) || [])[1];
345
- if (requires_subscription) videoObj.requires_subscription = requires_subscription;
346
- const live = (videoLiveRegex.exec(videoTag) || [])[1];
347
- if (live) videoObj.live = live;
348
- const tag = (videoTagRegex.exec(videoTag) || [])[1];
349
- if (tag) videoObj.tag = tag;
350
- const sources = [];
351
- let sourceMatch;
352
- while ((sourceMatch = sourceRegex.exec(videoContent)) !== null) {
353
- sources.push(sourceMatch[1]);
354
- }
355
- if (sources.length > 0) {
356
- videos.push(...sources.map((source) => {
357
- if (videoObj.thumbnail_loc) {
358
- videoObj.thumbnail_loc = resolveUrl(String(videoObj.thumbnail_loc));
359
- }
360
- return {
361
- ...videoObj,
362
- content_loc: resolveUrl(source)
363
- };
364
- }));
365
- } else {
366
- videos.push(videoObj);
367
- }
368
- }
369
- }
370
- const validVideos = videos.filter((v) => {
371
- return v.content_loc && v.thumbnail_loc && v.title && v.description;
372
- });
373
- if (validVideos.length > 0) {
374
- payload.videos = validVideos;
375
- }
376
- }
377
- if (options?.lastmod) {
378
- const articleModifiedTime = html.match(/<meta[^>]+property="article:modified_time"[^>]+content="([^"]+)"/)?.[1] || html.match(/<meta[^>]+content="([^"]+)"[^>]+property="article:modified_time"/)?.[1];
379
- if (articleModifiedTime)
380
- payload.lastmod = articleModifiedTime;
381
- }
382
- if (options?.alternatives) {
383
- const alternatives = (html.match(/<link[^>]+rel="alternate"[^>]+>/g) || []).map((a) => {
384
- const href = a.match(/href="([^"]+)"/)?.[1];
385
- const hreflang = a.match(/hreflang="([^"]+)"/)?.[1];
386
- return { hreflang, href: ufo.parseURL(href).pathname };
387
- }).filter((a) => a.hreflang && a.href);
388
- if (alternatives?.length && (alternatives.length > 1 || alternatives?.[0].hreflang !== "x-default"))
389
- payload.alternatives = alternatives;
390
- }
391
- return payload;
392
- }
393
-
394
- function formatPrerenderRoute(route) {
395
- let str = ` \u251C\u2500 ${route.route} (${route.generateTimeMS}ms)`;
396
- if (route.error) {
397
- const errorColor = chalk__default[route.error.statusCode === 404 ? "yellow" : "red"];
398
- const errorLead = "\u2514\u2500\u2500";
399
- str += `
400
- \u2502 ${errorLead} ${errorColor(route.error)}`;
401
- }
402
- return chalk__default.gray(str);
403
- }
404
- function includesSitemapRoot(sitemapName, routes) {
405
- return routes.includes(`/__sitemap__/`) || routes.includes(`/sitemap.xml`) || routes.includes(`/${sitemapName}`) || routes.includes("/sitemap_index.xml");
406
- }
407
- function isNuxtGenerate(nuxt = kit.useNuxt()) {
408
- return nuxt.options._generate || [
409
- "static",
410
- "github-pages"
411
- ].includes(resolveNitroPreset());
412
- }
413
- const NuxtRedirectHtmlRegex = /<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=([^"]+)"><\/head><\/html>/;
414
- function setupPrerenderHandler(_options, nuxt = kit.useNuxt()) {
415
- const { runtimeConfig: options, logger } = _options;
416
- const prerenderedRoutes = nuxt.options.nitro.prerender?.routes || [];
417
- let prerenderSitemap = isNuxtGenerate() || includesSitemapRoot(options.sitemapName, prerenderedRoutes);
418
- if (resolveNitroPreset() === "vercel-edge") {
419
- logger.warn("Runtime sitemaps are not supported on Vercel Edge, falling back to prerendering sitemaps.");
420
- prerenderSitemap = true;
421
- }
422
- if (nuxt.options.nitro.prerender?.routes)
423
- nuxt.options.nitro.prerender.routes = nuxt.options.nitro.prerender.routes.filter((r) => r && !includesSitemapRoot(options.sitemapName, [r]));
424
- nuxt.hooks.hook("nitro:init", async (nitro) => {
425
- let prerenderer;
426
- nitro.hooks.hook("prerender:init", async (_prerenderer) => {
427
- prerenderer = _prerenderer;
428
- });
429
- nitro.hooks.hook("prerender:generate", async (route) => {
430
- const html = route.contents;
431
- if (!route.fileName?.endsWith(".html") || !html || ["/200.html", "/404.html"].includes(route.route))
432
- return;
433
- if (html.match(NuxtRedirectHtmlRegex)) {
434
- return;
435
- }
436
- route._sitemap = defu.defu(route._sitemap, {
437
- loc: route.route
438
- });
439
- if (options.autoI18n && Object.keys(options.sitemaps).length > 1) {
440
- const path = route.route;
441
- const match = utilsPure_js.splitForLocales(path, options.autoI18n.locales.map((l) => l.code));
442
- const locale = match[0] || options.autoI18n.defaultLocale;
443
- if (options.isI18nMapped) {
444
- const { _sitemap } = options.autoI18n.locales.find((l) => l.code === locale) || { _sitemap: locale };
445
- route._sitemap._sitemap = _sitemap;
446
- }
447
- }
448
- route._sitemap = defu.defu(extractSitemapMetaFromHtml(html, {
449
- images: options.discoverImages,
450
- videos: options.discoverVideos,
451
- // TODO configurable?
452
- lastmod: true,
453
- alternatives: true,
454
- resolveUrl(s) {
455
- return s.startsWith("/") ? kit$1.withSiteUrl(s) : s;
456
- }
457
- }), route._sitemap);
458
- });
459
- nitro.hooks.hook("prerender:done", async () => {
460
- const isNuxt5 = nuxt.options._majorVersion === 5;
461
- let nitroModule;
462
- if (isNuxt5) {
463
- nitroModule = await import(String("nitro"));
464
- } else {
465
- nitroModule = await import(String("nitropack"));
466
- }
467
- if (!nitroModule) {
468
- return;
469
- }
470
- await nitroModule.build(prerenderer);
471
- const routes = [];
472
- if (options.debug)
473
- routes.push("/__sitemap__/debug.json");
474
- if (prerenderSitemap) {
475
- routes.push(
476
- options.isMultiSitemap ? "/sitemap_index.xml" : `/${Object.keys(options.sitemaps)[0]}`
477
- );
478
- }
479
- for (const route of routes)
480
- await prerenderRoute(nitro, route);
481
- });
482
- });
483
- }
484
- async function prerenderRoute(nitro, route) {
485
- const start = Date.now();
486
- const _route = { route, fileName: route };
487
- const encodedRoute = encodeURI(route);
488
- const res = await globalThis.$fetch.raw(
489
- ufo.withBase(encodedRoute, nitro.options.baseURL),
490
- {
491
- headers: { "x-nitro-prerender": encodedRoute },
492
- retry: nitro.options.prerender.retry,
493
- retryDelay: nitro.options.prerender.retryDelay
494
- }
495
- );
496
- const header = res.headers.get("x-nitro-prerender") || "";
497
- const prerenderUrls = [
498
- ...header.split(",").map((i) => i.trim()).map((i) => decodeURIComponent(i)).filter(Boolean)
499
- ];
500
- const filePath = node_path.join(nitro.options.output.publicDir, _route.fileName);
501
- await promises.mkdir(pathe.dirname(filePath), { recursive: true });
502
- const data = res._data;
503
- if (filePath.endsWith("json") || typeof data === "object")
504
- await promises.writeFile(filePath, JSON.stringify(data), "utf8");
505
- else
506
- await promises.writeFile(filePath, data, "utf8");
507
- _route.generateTimeMS = Date.now() - start;
508
- nitro._prerenderedRoutes.push(_route);
509
- nitro.logger.log(formatPrerenderRoute(_route));
510
- for (const url of prerenderUrls)
511
- await prerenderRoute(nitro, url);
512
- }
513
-
514
- const DEVTOOLS_UI_ROUTE = "/__sitemap__/devtools";
515
- const DEVTOOLS_UI_LOCAL_PORT = 3030;
516
- function setupDevToolsUI(options, resolve, nuxt = kit.useNuxt()) {
517
- const clientPath = resolve("./client");
518
- const isProductionBuild = node_fs.existsSync(clientPath);
519
- if (isProductionBuild) {
520
- nuxt.hook("vite:serverCreated", async (server) => {
521
- const sirv = await import('sirv').then((r) => r.default || r);
522
- server.middlewares.use(
523
- DEVTOOLS_UI_ROUTE,
524
- sirv(clientPath, { dev: true, single: true })
525
- );
526
- });
527
- } else {
528
- nuxt.hook("vite:extendConfig", (config) => {
529
- config.server = config.server || {};
530
- config.server.proxy = config.server.proxy || {};
531
- config.server.proxy[DEVTOOLS_UI_ROUTE] = {
532
- target: `http://localhost:${DEVTOOLS_UI_LOCAL_PORT}${DEVTOOLS_UI_ROUTE}`,
533
- changeOrigin: true,
534
- followRedirects: true,
535
- rewrite: (path) => path.replace(DEVTOOLS_UI_ROUTE, "")
536
- };
537
- });
538
- }
539
- nuxt.hook("devtools:customTabs", (tabs) => {
540
- tabs.push({
541
- // unique identifier
542
- name: "sitemap",
543
- // title to display in the tab
544
- title: "Sitemap",
545
- // any icon from Iconify, or a URL to an image
546
- icon: "carbon:load-balancer-application",
547
- // iframe view
548
- view: {
549
- type: "iframe",
550
- src: DEVTOOLS_UI_ROUTE
551
- }
552
- });
553
- });
554
- }
555
-
556
- function splitPathForI18nLocales(path, autoI18n) {
557
- const locales = autoI18n.strategy === "prefix_except_default" ? autoI18n.locales.filter((l) => l.code !== autoI18n.defaultLocale) : autoI18n.locales;
558
- if (typeof path !== "string" || path.startsWith("/_"))
559
- return path;
560
- const match = utilsPure_js.splitForLocales(path, locales.map((l) => l.code));
561
- const locale = match[0];
562
- if (locale)
563
- return path;
564
- return [
565
- path,
566
- ...locales.map((l) => `/${l.code}${path}`)
567
- ];
568
- }
569
- function generatePathForI18nPages(ctx) {
570
- const { localeCode, pageLocales, nuxtI18nConfig, forcedStrategy, normalisedLocales } = ctx;
571
- const locale = normalisedLocales.find((l) => l.code === localeCode);
572
- let path = pageLocales;
573
- switch (forcedStrategy ?? nuxtI18nConfig.strategy) {
574
- case "prefix_except_default":
575
- case "prefix_and_default":
576
- path = localeCode === nuxtI18nConfig.defaultLocale ? pageLocales : ufo.joinURL(localeCode, pageLocales);
577
- break;
578
- case "prefix":
579
- path = ufo.joinURL(localeCode, pageLocales);
580
- break;
581
- }
582
- return locale?.domain ? ufo.withHttps(ufo.withBase(path, locale.domain)) : path;
583
- }
584
- function normalizeLocales(nuxtI18nConfig) {
585
- let locales = nuxtI18nConfig.locales || [];
586
- let onlyLocales = nuxtI18nConfig?.bundle?.onlyLocales || [];
587
- onlyLocales = typeof onlyLocales === "string" ? [onlyLocales] : onlyLocales;
588
- locales = utilsPure_js.mergeOnKey(locales.map((locale) => typeof locale === "string" ? { code: locale } : locale), "code");
589
- if (onlyLocales.length) {
590
- locales = locales.filter((locale) => onlyLocales.includes(locale.code));
591
- }
592
- return locales.map((locale) => {
593
- if (locale.iso && !locale.language) {
594
- locale.language = locale.iso;
595
- }
596
- locale._hreflang = locale.language || locale.code;
597
- locale._sitemap = locale.language || locale.code;
598
- return locale;
599
- });
600
- }
601
-
602
- function isValidFilter(filter) {
603
- if (typeof filter === "string")
604
- return true;
605
- if (filter instanceof RegExp)
606
- return true;
607
- if (typeof filter === "object" && typeof filter.regex === "string")
608
- return true;
609
- return false;
610
- }
611
- function normalizeFilters(filters) {
612
- return (filters || []).map((filter) => {
613
- if (!isValidFilter(filter)) {
614
- console.warn(`[@nuxtjs/sitemap] You have provided an invalid filter: ${filter}, ignoring.`);
615
- return false;
616
- }
617
- return filter instanceof RegExp ? { regex: filter.toString() } : filter;
618
- }).filter(Boolean);
619
- }
620
-
621
- const module$1 = kit.defineNuxtModule({
622
- meta: {
623
- name: "@nuxtjs/sitemap",
624
- compatibility: {
625
- nuxt: ">=3.9.0",
626
- bridge: false
627
- },
628
- configKey: "sitemap"
629
- },
630
- defaults: {
631
- enabled: true,
632
- credits: true,
633
- cacheMaxAgeSeconds: 60 * 10,
634
- // cache for 10 minutes
635
- minify: false,
636
- debug: false,
637
- defaultSitemapsChunkSize: 1e3,
638
- autoLastmod: false,
639
- discoverImages: true,
640
- discoverVideos: true,
641
- urls: [],
642
- sortEntries: true,
643
- sitemapsPathPrefix: "/__sitemap__/",
644
- xsl: "/__sitemap__/style.xsl",
645
- xslTips: true,
646
- strictNuxtContentPaths: false,
647
- runtimeCacheStorage: true,
648
- sitemapName: "sitemap.xml",
649
- // cacheControlHeader: 'max-age=600, must-revalidate',
650
- defaults: {},
651
- // index sitemap options filtering
652
- include: [],
653
- exclude: ["/_**"],
654
- // sources
655
- sources: [],
656
- excludeAppSources: []
657
- },
658
- async setup(config, nuxt) {
659
- const { resolve } = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
660
- const { name, version } = await pkgTypes.readPackageJSON(resolve("../package.json"));
661
- const logger = kit.useLogger(name);
662
- logger.level = config.debug || nuxt.options.debug ? 4 : 3;
663
- if (config.enabled === false) {
664
- logger.debug("The module is disabled, skipping setup.");
665
- return;
666
- }
667
- config.exclude.push(`${ufo.withTrailingSlash(nuxt.options.app.buildAssetsDir)}**`);
668
- nuxt.options.alias["#sitemap"] = resolve("./runtime");
669
- nuxt.options.nitro.alias = nuxt.options.nitro.alias || {};
670
- nuxt.options.nitro.alias["#sitemap"] = resolve("./runtime");
671
- config.xslColumns = config.xslColumns || [
672
- { label: "URL", width: "50%" },
673
- { label: "Images", width: "25%", select: "count(image:image)" },
674
- {
675
- label: "Last Updated",
676
- width: "25%",
677
- select: "concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)),concat(' ', substring(sitemap:lastmod,20,6)))"
678
- }
679
- ];
680
- if (config.autoLastmod) {
681
- config.defaults = config.defaults || {};
682
- config.defaults.lastmod = normalise_js.normaliseDate(/* @__PURE__ */ new Date());
683
- }
684
- const normalizedSitemaps = typeof config.sitemaps === "boolean" ? {} : config.sitemaps || {};
685
- if (!nuxt.options._prepare && Object.keys(normalizedSitemaps).length) {
686
- const isSitemapIndexOnly = typeof normalizedSitemaps?.index !== "undefined" && Object.keys(normalizedSitemaps).length === 1;
687
- if (!isSitemapIndexOnly) {
688
- const warnForIgnoredKey = (key) => {
689
- logger.warn(`You are using multiple-sitemaps but have provided \`sitemap.${key}\` in your Nuxt config. This will be ignored, please move it to the child sitemap config.`);
690
- logger.warn("Learn more at: https://nuxtseo.com/sitemap/guides/multi-sitemaps");
691
- };
692
- switch (true) {
693
- case (config?.sources?.length || 0) > 0:
694
- warnForIgnoredKey("sources");
695
- break;
696
- case config?.includeAppSources !== void 0:
697
- warnForIgnoredKey("includeAppSources");
698
- break;
699
- }
700
- }
701
- }
702
- await kit$1.installNuxtSiteConfig();
703
- const userGlobalSources = [
704
- ...config.sources || []
705
- ];
706
- const appGlobalSources = [];
707
- nuxt.options.nitro.storage = nuxt.options.nitro.storage || {};
708
- if (config.runtimeCacheStorage && !nuxt.options.dev && typeof config.runtimeCacheStorage === "object")
709
- nuxt.options.nitro.storage.sitemap = config.runtimeCacheStorage;
710
- if (!config.sitemapName.endsWith("xml")) {
711
- const newName = `${config.sitemapName.split(".")[0]}.xml`;
712
- logger.warn(`You have provided a \`sitemapName\` that does not end with \`.xml\`. This is not supported by search engines, renaming to \`${newName}\`.`);
713
- config.sitemapName = newName;
714
- }
715
- config.sitemapName = ufo.withoutLeadingSlash(config.sitemapName);
716
- let usingMultiSitemaps = !!config.sitemaps;
717
- let isI18nMapped = false;
718
- let nuxtI18nConfig = {};
719
- let resolvedAutoI18n = typeof config.autoI18n === "boolean" ? false : config.autoI18n || false;
720
- const hasDisabledAutoI18n = typeof config.autoI18n === "boolean" && !config.autoI18n;
721
- let normalisedLocales = [];
722
- let usingI18nPages = false;
723
- const i18nModule = ["@nuxtjs/i18n", "nuxt-i18n-micro"].find((s) => kit.hasNuxtModule(s));
724
- if (i18nModule) {
725
- const i18nVersion = await kit.getNuxtModuleVersion(i18nModule);
726
- if (i18nVersion && i18nModule === "@nuxtjs/i18n" && !await kit.hasNuxtModuleCompatibility(i18nModule, ">=8"))
727
- logger.warn(`You are using ${i18nModule} v${i18nVersion}. For the best compatibility, please upgrade to ${i18nModule} v8.0.0 or higher.`);
728
- nuxtI18nConfig = await getNuxtModuleOptions(i18nModule) || {};
729
- if (typeof nuxtI18nConfig.includeDefaultLocaleRoute !== "undefined") {
730
- nuxtI18nConfig.strategy = nuxtI18nConfig.includeDefaultLocaleRoute ? "prefix" : "prefix_except_default";
731
- }
732
- normalisedLocales = normalizeLocales(nuxtI18nConfig);
733
- usingI18nPages = !!Object.keys(nuxtI18nConfig.pages || {}).length;
734
- if (usingI18nPages && !hasDisabledAutoI18n) {
735
- const i18nPagesSources = {
736
- context: {
737
- name: `${i18nModule}:pages`,
738
- description: "Generated from your i18n.pages config.",
739
- tips: [
740
- "You can disable this with `autoI18n: false`."
741
- ]
742
- },
743
- urls: []
744
- };
745
- for (const pageLocales of Object.values(nuxtI18nConfig?.pages)) {
746
- for (const localeCode in pageLocales) {
747
- const locale = normalisedLocales.find((l) => l.code === localeCode);
748
- if (!locale || !pageLocales[localeCode] || pageLocales[localeCode].includes("["))
749
- continue;
750
- const alternatives = Object.keys(pageLocales).filter((l) => pageLocales[l] !== false).map((l) => ({
751
- hreflang: normalisedLocales.find((nl) => nl.code === l)?._hreflang || l,
752
- href: generatePathForI18nPages({ localeCode: l, pageLocales: pageLocales[l], nuxtI18nConfig, normalisedLocales })
753
- }));
754
- if (alternatives.length && nuxtI18nConfig.defaultLocale && pageLocales[nuxtI18nConfig.defaultLocale] && pageLocales[nuxtI18nConfig.defaultLocale] !== false)
755
- alternatives.push({ hreflang: "x-default", href: generatePathForI18nPages({ normalisedLocales, localeCode: nuxtI18nConfig.defaultLocale, pageLocales: pageLocales[nuxtI18nConfig.defaultLocale], nuxtI18nConfig }) });
756
- i18nPagesSources.urls.push({
757
- _sitemap: locale._sitemap,
758
- loc: generatePathForI18nPages({ normalisedLocales, localeCode, pageLocales: pageLocales[localeCode], nuxtI18nConfig }),
759
- alternatives
760
- });
761
- if (nuxtI18nConfig.strategy === "prefix_and_default" && localeCode === nuxtI18nConfig.defaultLocale) {
762
- i18nPagesSources.urls.push({
763
- _sitemap: locale._sitemap,
764
- loc: generatePathForI18nPages({ normalisedLocales, localeCode, pageLocales: pageLocales[localeCode], nuxtI18nConfig, forcedStrategy: "prefix" }),
765
- alternatives
766
- });
767
- }
768
- }
769
- }
770
- appGlobalSources.push(i18nPagesSources);
771
- if (Array.isArray(config.excludeAppSources))
772
- config.excludeAppSources.push("nuxt:pages");
773
- } else {
774
- if (!normalisedLocales.length)
775
- logger.warn(`You are using ${i18nModule} but have not configured any locales, this will cause issues with ${name}. Please configure \`locales\`.`);
776
- }
777
- const hasSetAutoI18n = typeof config.autoI18n === "object" && Object.keys(config.autoI18n).length;
778
- const hasI18nConfigForAlternatives = nuxtI18nConfig.differentDomains || usingI18nPages || nuxtI18nConfig.strategy !== "no_prefix" && nuxtI18nConfig.locales;
779
- if (!hasSetAutoI18n && !hasDisabledAutoI18n && hasI18nConfigForAlternatives) {
780
- resolvedAutoI18n = {
781
- differentDomains: nuxtI18nConfig.differentDomains,
782
- defaultLocale: nuxtI18nConfig.defaultLocale,
783
- locales: normalisedLocales,
784
- strategy: nuxtI18nConfig.strategy,
785
- // @ts-expect-error untyped
786
- pages: nuxtI18nConfig.pages
787
- };
788
- }
789
- let canI18nMap = config.sitemaps !== false && nuxtI18nConfig.strategy !== "no_prefix";
790
- if (typeof config.sitemaps === "object") {
791
- const isSitemapIndexOnly = typeof config.sitemaps.index !== "undefined" && Object.keys(config.sitemaps).length === 1;
792
- if (!isSitemapIndexOnly)
793
- canI18nMap = false;
794
- }
795
- if (canI18nMap && resolvedAutoI18n) {
796
- config.sitemaps = { index: [...config.sitemaps?.index || [], ...config.appendSitemaps || []] };
797
- for (const locale of resolvedAutoI18n.locales)
798
- config.sitemaps[locale._sitemap] = { includeAppSources: true };
799
- isI18nMapped = true;
800
- usingMultiSitemaps = true;
801
- }
802
- }
803
- nuxt.hooks.hook("robots:config", (robotsConfig) => {
804
- robotsConfig.sitemap.push(usingMultiSitemaps ? "/sitemap_index.xml" : `/${config.sitemapName}`);
805
- });
806
- nuxt.hooks.hook("modules:done", async () => {
807
- const robotsModuleName = ["nuxt-simple-robots", "@nuxtjs/robots"].find((s) => kit.hasNuxtModule(s));
808
- let needsRobotsPolyfill = true;
809
- if (robotsModuleName) {
810
- const robotsVersion = await kit.getNuxtModuleVersion(robotsModuleName);
811
- if (robotsVersion && !await kit.hasNuxtModuleCompatibility(robotsModuleName, ">=4"))
812
- logger.warn(`You are using ${robotsModuleName} v${robotsVersion}. For the best compatibility, please upgrade to ${robotsModuleName} v4.0.0 or higher.`);
813
- else
814
- needsRobotsPolyfill = false;
815
- }
816
- if (needsRobotsPolyfill) {
817
- kit.addServerImports([{
818
- name: "getPathRobotConfigPolyfill",
819
- as: "getPathRobotConfig",
820
- from: resolve("./runtime/server/composables/getPathRobotConfigPolyfill")
821
- }]);
822
- }
823
- });
824
- extendTypes(name, async ({ typesPath }) => {
825
- return `
826
- declare module 'nitropack' {
827
- interface PrerenderRoute {
828
- _sitemap?: import('${typesPath}').SitemapUrl
829
- }
830
- interface NitroRouteRules {
831
- index?: boolean
832
- sitemap?: import('${typesPath}').SitemapItemDefaults
833
- }
834
- interface NitroRouteConfig {
835
- index?: boolean
836
- sitemap?: import('${typesPath}').SitemapItemDefaults
837
- }
838
- interface NitroRuntimeHooks {
839
- 'sitemap:index-resolved': (ctx: import('${typesPath}').SitemapIndexRenderCtx) => void | Promise<void>
840
- 'sitemap:input': (ctx: import('${typesPath}').SitemapInputCtx) => void | Promise<void>
841
- 'sitemap:resolved': (ctx: import('${typesPath}').SitemapRenderCtx) => void | Promise<void>
842
- 'sitemap:output': (ctx: import('${typesPath}').SitemapOutputHookCtx) => void | Promise<void>
843
- 'sitemap:sources': (ctx: import('${typesPath}').SitemapSourcesHookCtx) => void | Promise<void>
844
- }
845
- }
846
- declare module 'vue-router' {
847
- interface RouteMeta {
848
- sitemap?: import('${typesPath}').SitemapItemDefaults
849
- }
850
- }
851
- `;
852
- });
853
- const prerenderedRoutes = nuxt.options.nitro.prerender?.routes || [];
854
- const prerenderSitemap = isNuxtGenerate() || includesSitemapRoot(config.sitemapName, prerenderedRoutes);
855
- const routeRules = {};
856
- nuxt.options.nitro.routeRules = nuxt.options.nitro.routeRules || {};
857
- if (prerenderSitemap) {
858
- routeRules.headers = {
859
- "Content-Type": "text/xml; charset=UTF-8",
860
- "Cache-Control": config.cacheMaxAgeSeconds ? `public, max-age=${config.cacheMaxAgeSeconds}, must-revalidate` : "no-cache, no-store",
861
- "X-Sitemap-Prerendered": (/* @__PURE__ */ new Date()).toISOString()
862
- };
863
- }
864
- if (config.xsl) {
865
- nuxt.options.nitro.routeRules[config.xsl] = {
866
- headers: {
867
- "Content-Type": "application/xslt+xml"
868
- }
869
- };
870
- }
871
- if (usingMultiSitemaps) {
872
- nuxt.options.nitro.routeRules["/sitemap.xml"] = { redirect: "/sitemap_index.xml" };
873
- nuxt.options.nitro.routeRules["/sitemap_index.xml"] = routeRules;
874
- if (typeof config.sitemaps === "object") {
875
- for (const k in config.sitemaps) {
876
- if (k === "index")
877
- continue;
878
- nuxt.options.nitro.routeRules[ufo.joinURL(config.sitemapsPathPrefix || "", `/${k}.xml`)] = routeRules;
879
- const sitemapConfig = config.sitemaps[k];
880
- if (sitemapConfig.chunks) {
881
- nuxt.options.nitro.routeRules[ufo.joinURL(config.sitemapsPathPrefix || "", `/${k}-*.xml`)] = routeRules;
882
- }
883
- }
884
- } else {
885
- nuxt.options.nitro.routeRules[ufo.joinURL(config.sitemapsPathPrefix || "", `/[0-9]+.xml`)] = routeRules;
886
- }
887
- } else {
888
- nuxt.options.nitro.routeRules[`/${config.sitemapName}`] = routeRules;
889
- }
890
- if (config.experimentalWarmUp)
891
- kit.addServerPlugin(resolve("./runtime/server/plugins/warm-up"));
892
- if (config.experimentalCompression)
893
- kit.addServerPlugin(resolve("./runtime/server/plugins/compression"));
894
- const isNuxtContentDocumentDriven = !!nuxt.options.content?.documentDriven || config.strictNuxtContentPaths;
895
- const usingNuxtContent = kit.hasNuxtModule("@nuxt/content");
896
- const isNuxtContentV3 = usingNuxtContent && await kit.hasNuxtModuleCompatibility("@nuxt/content", "^3");
897
- const nuxtV3Collections = /* @__PURE__ */ new Set();
898
- const isNuxtContentV2 = usingNuxtContent && await kit.hasNuxtModuleCompatibility("@nuxt/content", "^2");
899
- if (isNuxtContentV3) {
900
- if (nuxt.options._installedModules.some((m) => m.meta.name === "Content")) {
901
- logger.warn("You have loaded `@nuxt/content` before `@nuxtjs/sitemap`, this may cause issues with the integration. Please ensure `@nuxtjs/sitemap` is loaded first.");
902
- }
903
- config.exclude.push("/__nuxt_content/**");
904
- nuxt.options.alias["#sitemap/content-v3-nitro-path"] = resolve(pathe.dirname(kit.resolveModule("@nuxt/content")), "runtime/nitro");
905
- nuxt.hooks.hook("content:file:afterParse", (ctx) => {
906
- const content = ctx.content;
907
- nuxtV3Collections.add(ctx.collection.name);
908
- if (String(ctx.content.path).includes("/.")) {
909
- ctx.content.sitemap = null;
910
- return;
911
- }
912
- if (!("sitemap" in ctx.collection.fields)) {
913
- ctx.content.sitemap = null;
914
- return;
915
- }
916
- if (typeof content.sitemap !== "undefined" && !content.sitemap) {
917
- ctx.content.sitemap = null;
918
- return;
919
- }
920
- if (ctx.content.robots === false) {
921
- ctx.content.sitemap = null;
922
- return;
923
- }
924
- const images = [];
925
- if (config.discoverImages) {
926
- images.push(
927
- ...content.body.value?.filter(
928
- (c) => ["image", "img", "nuxtimg", "nuxt-img"].includes(c[0])
929
- ).filter((c) => c[1]?.src).map((c) => ({ loc: c[1].src })) || []
930
- );
931
- }
932
- const lastmod = content.seo?.articleModifiedTime || content.updatedAt;
933
- const defaults = {
934
- loc: content.path
935
- };
936
- if (images.length > 0)
937
- defaults.images = images;
938
- if (lastmod)
939
- defaults.lastmod = lastmod;
940
- ctx.content.sitemap = defu.defu(typeof content.sitemap === "object" ? content.sitemap : {}, defaults);
941
- });
942
- kit.addServerHandler({
943
- route: "/__sitemap__/nuxt-content-urls.json",
944
- handler: resolve("./runtime/server/routes/__sitemap__/nuxt-content-urls-v3")
945
- });
946
- if (config.strictNuxtContentPaths) {
947
- logger.warn("You have set `strictNuxtContentPaths: true` but are using @nuxt/content v3. This is not required, please remove it.");
948
- }
949
- appGlobalSources.push({
950
- context: {
951
- name: "@nuxt/content@v3:urls",
952
- description: "Generated from your markdown files.",
953
- tips: [`Parsing the following collections: ${Array.from(nuxtV3Collections).join(", ")}`]
954
- },
955
- fetch: "/__sitemap__/nuxt-content-urls.json"
956
- });
957
- } else if (isNuxtContentV2) {
958
- kit.addServerPlugin(resolve("./runtime/server/plugins/nuxt-content-v2"));
959
- kit.addServerHandler({
960
- route: "/__sitemap__/nuxt-content-urls.json",
961
- handler: resolve("./runtime/server/routes/__sitemap__/nuxt-content-urls-v2")
962
- });
963
- const tips = [];
964
- if (nuxt.options.content?.documentDriven)
965
- tips.push("Enabled because you're using `@nuxt/content` with `documentDriven: true`.");
966
- else if (config.strictNuxtContentPaths)
967
- tips.push("Enabled because you've set `config.strictNuxtContentPaths: true`.");
968
- else
969
- tips.push("You can provide a `sitemap` key in your markdown frontmatter to configure specific URLs. Make sure you include a `loc`.");
970
- appGlobalSources.push({
971
- context: {
972
- name: "@nuxt/content@v2:urls",
973
- description: "Generated from your markdown files.",
974
- tips
975
- },
976
- fetch: "/__sitemap__/nuxt-content-urls.json"
977
- });
978
- }
979
- const sitemaps = {};
980
- if (usingMultiSitemaps) {
981
- kit.addServerHandler({
982
- route: "/sitemap_index.xml",
983
- handler: resolve("./runtime/server/routes/sitemap_index.xml"),
984
- lazy: true,
985
- middleware: false
986
- });
987
- if (config.sitemapsPathPrefix && config.sitemapsPathPrefix !== "/") {
988
- kit.addServerHandler({
989
- route: ufo.joinURL(config.sitemapsPathPrefix, `/**:sitemap`),
990
- handler: resolve("./runtime/server/routes/sitemap/[sitemap].xml"),
991
- lazy: true,
992
- middleware: false
993
- });
994
- } else {
995
- const sitemapNames = Object.keys(config.sitemaps || {});
996
- for (const sitemapName of sitemapNames) {
997
- if (sitemapName === "index")
998
- continue;
999
- const sitemapConfig = config.sitemaps[sitemapName];
1000
- kit.addServerHandler({
1001
- route: ufo.withLeadingSlash(`${sitemapName}.xml`),
1002
- handler: resolve("./runtime/server/routes/sitemap/[sitemap].xml"),
1003
- lazy: true,
1004
- middleware: false
1005
- });
1006
- if (sitemapConfig.chunks) {
1007
- kit.addServerHandler({
1008
- route: `/${sitemapName}-*.xml`,
1009
- handler: resolve("./runtime/server/routes/sitemap/[sitemap].xml"),
1010
- lazy: true,
1011
- middleware: false
1012
- });
1013
- }
1014
- }
1015
- }
1016
- sitemaps.index = {
1017
- sitemapName: "index",
1018
- _route: ufo.withBase("sitemap_index.xml", nuxt.options.app.baseURL || "/"),
1019
- // @ts-expect-error untyped
1020
- sitemaps: [...config.sitemaps.index || [], ...config.appendSitemaps || []]
1021
- };
1022
- if (typeof config.sitemaps === "object") {
1023
- for (const sitemapName in config.sitemaps) {
1024
- if (sitemapName === "index")
1025
- continue;
1026
- const definition = config.sitemaps[sitemapName];
1027
- const sitemapConfig = defu.defu(
1028
- {
1029
- sitemapName,
1030
- _route: ufo.withBase(ufo.joinURL(config.sitemapsPathPrefix || "", `${sitemapName}.xml`), nuxt.options.app.baseURL || "/"),
1031
- _hasSourceChunk: typeof definition.urls !== "undefined" || definition.sources?.length
1032
- },
1033
- { ...definition, urls: void 0, sources: void 0 },
1034
- { include: config.include, exclude: config.exclude }
1035
- );
1036
- if (definition.chunks) {
1037
- let chunkSize = config.defaultSitemapsChunkSize || 1e3;
1038
- if (typeof definition.chunks === "number") {
1039
- if (definition.chunks <= 0) {
1040
- logger.warn(`Invalid chunks value (${definition.chunks}) for sitemap "${sitemapName}". Using default.`);
1041
- } else {
1042
- chunkSize = definition.chunks;
1043
- }
1044
- }
1045
- if (definition.chunkSize !== void 0) {
1046
- if (typeof definition.chunkSize !== "number" || definition.chunkSize <= 0) {
1047
- logger.warn(`Invalid chunkSize value (${definition.chunkSize}) for sitemap "${sitemapName}". Using default.`);
1048
- } else {
1049
- chunkSize = definition.chunkSize;
1050
- }
1051
- }
1052
- sitemapConfig._isChunking = true;
1053
- sitemapConfig._chunkSize = chunkSize;
1054
- sitemapConfig.chunks = definition.chunks;
1055
- sitemapConfig.chunkSize = definition.chunkSize;
1056
- }
1057
- sitemaps[sitemapName] = sitemapConfig;
1058
- }
1059
- } else {
1060
- sitemaps.chunks = {
1061
- sitemapName: "chunks",
1062
- defaults: config.defaults,
1063
- include: config.include,
1064
- exclude: config.exclude,
1065
- includeAppSources: true
1066
- };
1067
- }
1068
- } else {
1069
- sitemaps[config.sitemapName] = {
1070
- sitemapName: config.sitemapName,
1071
- route: ufo.withBase(config.sitemapName, nuxt.options.app.baseURL || "/"),
1072
- // will contain the xml
1073
- defaults: config.defaults,
1074
- include: config.include,
1075
- exclude: config.exclude,
1076
- includeAppSources: true
1077
- };
1078
- }
1079
- if (resolvedAutoI18n && usingI18nPages && !hasDisabledAutoI18n) {
1080
- const pages = nuxtI18nConfig?.pages || {};
1081
- for (const sitemapName in sitemaps) {
1082
- let mapToI18nPages = function(path) {
1083
- if (typeof path !== "string")
1084
- return [path];
1085
- const withoutSlashes = ufo.withoutTrailingSlash(ufo.withoutLeadingSlash(path)).replace("/index", "");
1086
- if (pages && withoutSlashes in pages) {
1087
- const pageLocales = pages[withoutSlashes];
1088
- if (pageLocales) {
1089
- return Object.keys(pageLocales).map((localeCode) => ufo.withLeadingSlash(generatePathForI18nPages({
1090
- localeCode,
1091
- pageLocales: pageLocales[localeCode],
1092
- nuxtI18nConfig,
1093
- normalisedLocales
1094
- })));
1095
- }
1096
- }
1097
- let match = [path];
1098
- Object.values(pages).forEach((pageLocales) => {
1099
- if (pageLocales && nuxtI18nConfig.defaultLocale in pageLocales && pageLocales[nuxtI18nConfig.defaultLocale] === path)
1100
- match = Object.keys(pageLocales).map((localeCode) => ufo.withLeadingSlash(generatePathForI18nPages({ localeCode, pageLocales: pageLocales[localeCode], nuxtI18nConfig, normalisedLocales })));
1101
- });
1102
- return match;
1103
- };
1104
- if (["index", "chunks"].includes(sitemapName))
1105
- continue;
1106
- const sitemap = sitemaps[sitemapName];
1107
- sitemap.include = (sitemap.include || []).flatMap((path) => mapToI18nPages(path));
1108
- sitemap.exclude = (sitemap.exclude || []).flatMap((path) => mapToI18nPages(path));
1109
- }
1110
- }
1111
- if (resolvedAutoI18n && resolvedAutoI18n.locales && resolvedAutoI18n.strategy !== "no_prefix") {
1112
- const i18n = resolvedAutoI18n;
1113
- for (const sitemapName in sitemaps) {
1114
- if (["index", "chunks"].includes(sitemapName))
1115
- continue;
1116
- const sitemap = sitemaps[sitemapName];
1117
- sitemap.include = (sitemap.include || []).map((path) => splitPathForI18nLocales(path, i18n)).flat();
1118
- sitemap.exclude = (sitemap.exclude || []).map((path) => splitPathForI18nLocales(path, i18n)).flat();
1119
- }
1120
- }
1121
- for (const sitemapName in sitemaps) {
1122
- const sitemap = sitemaps[sitemapName];
1123
- sitemap.include = normalizeFilters(sitemap.include);
1124
- sitemap.exclude = normalizeFilters(sitemap.exclude);
1125
- }
1126
- const runtimeConfig = {
1127
- isI18nMapped,
1128
- sitemapName: config.sitemapName,
1129
- isMultiSitemap: usingMultiSitemaps,
1130
- excludeAppSources: config.excludeAppSources,
1131
- cacheMaxAgeSeconds: nuxt.options.dev ? 0 : config.cacheMaxAgeSeconds,
1132
- autoLastmod: config.autoLastmod,
1133
- defaultSitemapsChunkSize: config.defaultSitemapsChunkSize,
1134
- minify: config.minify,
1135
- sortEntries: config.sortEntries,
1136
- debug: config.debug,
1137
- // needed for nuxt/content integration and prerendering
1138
- discoverImages: config.discoverImages,
1139
- discoverVideos: config.discoverVideos,
1140
- sitemapsPathPrefix: config.sitemapsPathPrefix,
1141
- /* @nuxt/content */
1142
- isNuxtContentDocumentDriven,
1143
- /* xsl styling */
1144
- xsl: config.xsl,
1145
- xslTips: config.xslTips,
1146
- xslColumns: config.xslColumns,
1147
- credits: config.credits,
1148
- version,
1149
- sitemaps
1150
- };
1151
- if (resolvedAutoI18n)
1152
- runtimeConfig.autoI18n = resolvedAutoI18n;
1153
- nuxt.options.runtimeConfig.sitemap = runtimeConfig;
1154
- if (config.debug || nuxt.options.dev) {
1155
- kit.addServerHandler({
1156
- route: "/__sitemap__/debug.json",
1157
- handler: resolve("./runtime/server/routes/__sitemap__/debug")
1158
- });
1159
- if (usingMultiSitemaps) {
1160
- kit.addServerHandler({
1161
- route: "/__sitemap__/**:sitemap",
1162
- handler: resolve("./runtime/server/routes/sitemap/[sitemap].xml"),
1163
- lazy: true,
1164
- middleware: true
1165
- });
1166
- }
1167
- setupDevToolsUI(config, resolve);
1168
- }
1169
- const imports = [
1170
- {
1171
- from: resolve("./runtime/server/composables/defineSitemapEventHandler"),
1172
- name: "defineSitemapEventHandler"
1173
- },
1174
- {
1175
- from: resolve("./runtime/server/composables/asSitemapUrl"),
1176
- name: "asSitemapUrl"
1177
- }
1178
- ];
1179
- kit.addServerImports(imports);
1180
- const pagesPromise = createPagesPromise();
1181
- const nitroPromise = createNitroPromise();
1182
- let resolvedConfigUrls = false;
1183
- nuxt.hooks.hook("nitro:config", (nitroConfig) => {
1184
- nitroConfig.virtual["#sitemap-virtual/global-sources.mjs"] = async () => {
1185
- const { prerenderUrls, routeRules: routeRules2 } = generateExtraRoutesFromNuxtConfig();
1186
- const prerenderUrlsFinal = [
1187
- ...prerenderUrls,
1188
- ...((await nitroPromise)._prerenderedRoutes || []).filter((r) => {
1189
- const lastSegment = r.route.split("/").pop();
1190
- const isExplicitFile = !!lastSegment?.match(/\.[0-9a-z]+$/i)?.[0];
1191
- if (isExplicitFile || r.error || ["/200.html", "/404.html", "/index.html"].includes(r.route))
1192
- return false;
1193
- return r.contentType?.includes("text/html");
1194
- }).map((r) => r._sitemap)
1195
- ];
1196
- const pageSource = convertNuxtPagesToSitemapEntries(await pagesPromise, {
1197
- isI18nMapped,
1198
- autoLastmod: config.autoLastmod,
1199
- defaultLocale: nuxtI18nConfig.defaultLocale || "en",
1200
- strategy: nuxtI18nConfig.strategy || "no_prefix",
1201
- routesNameSeparator: nuxtI18nConfig.routesNameSeparator,
1202
- normalisedLocales,
1203
- filter: {
1204
- include: normalizeFilters(config.include),
1205
- exclude: normalizeFilters(config.exclude)
1206
- },
1207
- isI18nMicro: i18nModule === "nuxt-i18n-micro"
1208
- });
1209
- if (!pageSource.length) {
1210
- pageSource.push(nuxt.options.app.baseURL || "/");
1211
- }
1212
- if (!resolvedConfigUrls && config.urls) {
1213
- if (config.urls) {
1214
- userGlobalSources.push({
1215
- context: {
1216
- name: "sitemap:urls",
1217
- description: "Set with the `sitemap.urls` config."
1218
- },
1219
- urls: await resolveUrls(config.urls, { path: "sitemap:urls", logger })
1220
- });
1221
- }
1222
- resolvedConfigUrls = true;
1223
- }
1224
- const globalSources = [
1225
- ...userGlobalSources.map((s) => {
1226
- if (typeof s === "string" || Array.isArray(s)) {
1227
- return {
1228
- sourceType: "user",
1229
- fetch: s
1230
- };
1231
- }
1232
- s.sourceType = "user";
1233
- return s;
1234
- }),
1235
- ...(config.excludeAppSources === true ? [] : [
1236
- ...appGlobalSources,
1237
- {
1238
- context: {
1239
- name: "nuxt:pages",
1240
- description: "Generated from your static page files.",
1241
- tips: [
1242
- "Can be disabled with `{ excludeAppSources: ['nuxt:pages'] }`."
1243
- ]
1244
- },
1245
- urls: pageSource
1246
- },
1247
- {
1248
- context: {
1249
- name: "nuxt:route-rules",
1250
- description: "Generated from your route rules config.",
1251
- tips: [
1252
- "Can be disabled with `{ excludeAppSources: ['nuxt:route-rules'] }`."
1253
- ]
1254
- },
1255
- urls: routeRules2
1256
- },
1257
- {
1258
- context: {
1259
- name: "nuxt:prerender",
1260
- description: "Generated at build time when prerendering.",
1261
- tips: [
1262
- "Can be disabled with `{ excludeAppSources: ['nuxt:prerender'] }`."
1263
- ]
1264
- },
1265
- urls: prerenderUrlsFinal
1266
- }
1267
- ]).filter((s) => !config.excludeAppSources.includes(s.context.name) && (!!s.urls?.length || !!s.fetch)).map((s) => {
1268
- s.sourceType = "app";
1269
- return s;
1270
- })
1271
- ];
1272
- return `export const sources = ${JSON.stringify(globalSources, null, 4)}`;
1273
- };
1274
- const extraSitemapModules = typeof config.sitemaps == "object" ? Object.keys(config.sitemaps).filter((n) => n !== "index") : [];
1275
- const sitemapSources = {};
1276
- nitroConfig.virtual[`#sitemap-virtual/child-sources.mjs`] = async () => {
1277
- for (const sitemapName of extraSitemapModules) {
1278
- sitemapSources[sitemapName] = sitemapSources[sitemapName] || [];
1279
- const definition = config.sitemaps[sitemapName];
1280
- if (!sitemapSources[sitemapName].length) {
1281
- if (definition.urls) {
1282
- sitemapSources[sitemapName].push({
1283
- context: {
1284
- name: `sitemaps:${sitemapName}:urls`,
1285
- description: "Set with the `sitemap.urls` config."
1286
- },
1287
- urls: await resolveUrls(definition.urls, { path: `sitemaps:${sitemapName}:urls`, logger })
1288
- });
1289
- }
1290
- sitemapSources[sitemapName].push(
1291
- ...(definition.sources || []).map((s) => {
1292
- if (typeof s === "string" || Array.isArray(s)) {
1293
- return {
1294
- sourceType: "user",
1295
- fetch: s
1296
- };
1297
- }
1298
- s.sourceType = "user";
1299
- return s;
1300
- })
1301
- );
1302
- }
1303
- }
1304
- return `export const sources = ${JSON.stringify(sitemapSources, null, 4)}`;
1305
- };
1306
- });
1307
- if (config.xsl === "/__sitemap__/style.xsl") {
1308
- kit.addServerHandler({
1309
- route: config.xsl,
1310
- handler: resolve("./runtime/server/routes/sitemap.xsl")
1311
- });
1312
- config.xsl = ufo.withBase(config.xsl, nuxt.options.app.baseURL);
1313
- if (prerenderSitemap)
1314
- kit.addPrerenderRoutes(config.xsl);
1315
- }
1316
- kit.addServerHandler({
1317
- route: `/${config.sitemapName}`,
1318
- handler: resolve("./runtime/server/routes/sitemap.xml")
1319
- });
1320
- setupPrerenderHandler({ runtimeConfig, logger });
1321
- }
1322
- });
1323
-
1324
- module.exports = module$1;