@nuxtjs/sitemap 7.4.5 → 7.4.8

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