@nuxtjs/sitemap 7.4.5 → 7.4.7

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