@nuxtjs/sitemap 7.4.0 → 7.4.1

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