@nuxtjs/sitemap 7.4.4 → 7.4.5
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/package.json +3 -3
- package/dist/client/200.html +0 -1
- package/dist/client/404.html +0 -1
- package/dist/client/__sitemap__/style.xsl +0 -190
- package/dist/client/_nuxt/BRTu1kzH.js +0 -172
- package/dist/client/_nuxt/CVMmb_pX.js +0 -1
- package/dist/client/_nuxt/CVO1_9PV.js +0 -1
- package/dist/client/_nuxt/Cp-IABpG.js +0 -1
- package/dist/client/_nuxt/D0r3Knsf.js +0 -1
- package/dist/client/_nuxt/builds/latest.json +0 -1
- package/dist/client/_nuxt/builds/meta/7faab852-f8a4-43e6-a124-2cd93df90673.json +0 -1
- package/dist/client/_nuxt/entry.D5V0t8Hh.css +0 -1
- package/dist/client/_nuxt/error-404.BXx3NK2Z.css +0 -1
- package/dist/client/_nuxt/error-500.BYrbHUTO.css +0 -1
- package/dist/client/_nuxt/rHMUQZkV.js +0 -1
- package/dist/client/index.html +0 -1
- package/dist/client/sitemap.xml +0 -7
- package/dist/content.d.mts +0 -232
- package/dist/content.d.ts +0 -232
- package/dist/content.mjs +0 -45
- package/dist/module.d.mts +0 -10
- package/dist/module.d.ts +0 -10
- package/dist/module.json +0 -12
- package/dist/module.mjs +0 -1217
- package/dist/runtime/server/composables/asSitemapUrl.d.ts +0 -2
- package/dist/runtime/server/composables/asSitemapUrl.js +0 -3
- package/dist/runtime/server/composables/defineSitemapEventHandler.d.ts +0 -4
- package/dist/runtime/server/composables/defineSitemapEventHandler.js +0 -2
- package/dist/runtime/server/content-compat.d.ts +0 -1
- package/dist/runtime/server/content-compat.js +0 -2
- package/dist/runtime/server/kit.d.ts +0 -3
- package/dist/runtime/server/kit.js +0 -25
- package/dist/runtime/server/plugins/compression.d.ts +0 -2
- package/dist/runtime/server/plugins/compression.js +0 -8
- package/dist/runtime/server/plugins/nuxt-content-v2.d.ts +0 -2
- package/dist/runtime/server/plugins/nuxt-content-v2.js +0 -39
- package/dist/runtime/server/plugins/warm-up.d.ts +0 -2
- package/dist/runtime/server/plugins/warm-up.js +0 -39
- package/dist/runtime/server/robots-polyfill/getPathRobotConfig.d.ts +0 -5
- package/dist/runtime/server/robots-polyfill/getPathRobotConfig.js +0 -3
- package/dist/runtime/server/routes/__sitemap__/debug.d.ts +0 -40
- package/dist/runtime/server/routes/__sitemap__/debug.js +0 -29
- package/dist/runtime/server/routes/__sitemap__/nuxt-content-urls-v2.d.ts +0 -2
- package/dist/runtime/server/routes/__sitemap__/nuxt-content-urls-v2.js +0 -6
- package/dist/runtime/server/routes/__sitemap__/nuxt-content-urls-v3.d.ts +0 -2
- package/dist/runtime/server/routes/__sitemap__/nuxt-content-urls-v3.js +0 -24
- package/dist/runtime/server/routes/sitemap/[sitemap].xml.d.ts +0 -2
- package/dist/runtime/server/routes/sitemap/[sitemap].xml.js +0 -50
- package/dist/runtime/server/routes/sitemap.xml.d.ts +0 -2
- package/dist/runtime/server/routes/sitemap.xml.js +0 -13
- package/dist/runtime/server/routes/sitemap.xsl.d.ts +0 -2
- package/dist/runtime/server/routes/sitemap.xsl.js +0 -255
- package/dist/runtime/server/routes/sitemap_index.xml.d.ts +0 -2
- package/dist/runtime/server/routes/sitemap_index.xml.js +0 -42
- package/dist/runtime/server/sitemap/builder/sitemap-index.d.ts +0 -13
- package/dist/runtime/server/sitemap/builder/sitemap-index.js +0 -197
- package/dist/runtime/server/sitemap/builder/sitemap.d.ts +0 -16
- package/dist/runtime/server/sitemap/builder/sitemap.js +0 -241
- package/dist/runtime/server/sitemap/builder/xml.d.ts +0 -6
- package/dist/runtime/server/sitemap/builder/xml.js +0 -197
- package/dist/runtime/server/sitemap/nitro.d.ts +0 -4
- package/dist/runtime/server/sitemap/nitro.js +0 -144
- package/dist/runtime/server/sitemap/urlset/normalise.d.ts +0 -6
- package/dist/runtime/server/sitemap/urlset/normalise.js +0 -137
- package/dist/runtime/server/sitemap/urlset/sort.d.ts +0 -2
- package/dist/runtime/server/sitemap/urlset/sort.js +0 -13
- package/dist/runtime/server/sitemap/urlset/sources.d.ts +0 -6
- package/dist/runtime/server/sitemap/urlset/sources.js +0 -143
- package/dist/runtime/server/sitemap/utils/chunk.d.ts +0 -10
- package/dist/runtime/server/sitemap/utils/chunk.js +0 -67
- package/dist/runtime/server/tsconfig.json +0 -3
- package/dist/runtime/server/utils.d.ts +0 -5
- package/dist/runtime/server/utils.js +0 -16
- package/dist/runtime/types.d.ts +0 -458
- package/dist/runtime/types.js +0 -0
- package/dist/runtime/utils-pure.d.ts +0 -14
- package/dist/runtime/utils-pure.js +0 -85
- package/dist/shared/sitemap.DR3_6qqU.mjs +0 -212
- package/dist/types.d.mts +0 -5
- package/dist/utils.d.mts +0 -28
- package/dist/utils.d.ts +0 -28
- package/dist/utils.mjs +0 -368
package/dist/module.mjs
DELETED
|
@@ -1,1217 +0,0 @@
|
|
|
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
|
-
},
|
|
505
|
-
defaults: {
|
|
506
|
-
enabled: true,
|
|
507
|
-
credits: true,
|
|
508
|
-
cacheMaxAgeSeconds: 60 * 10,
|
|
509
|
-
// cache for 10 minutes
|
|
510
|
-
minify: false,
|
|
511
|
-
debug: false,
|
|
512
|
-
defaultSitemapsChunkSize: 1e3,
|
|
513
|
-
autoLastmod: false,
|
|
514
|
-
discoverImages: true,
|
|
515
|
-
discoverVideos: true,
|
|
516
|
-
urls: [],
|
|
517
|
-
sortEntries: true,
|
|
518
|
-
sitemapsPathPrefix: "/__sitemap__/",
|
|
519
|
-
xsl: "/__sitemap__/style.xsl",
|
|
520
|
-
xslTips: true,
|
|
521
|
-
strictNuxtContentPaths: false,
|
|
522
|
-
runtimeCacheStorage: true,
|
|
523
|
-
sitemapName: "sitemap.xml",
|
|
524
|
-
// cacheControlHeader: 'max-age=600, must-revalidate',
|
|
525
|
-
defaults: {},
|
|
526
|
-
// index sitemap options filtering
|
|
527
|
-
include: [],
|
|
528
|
-
exclude: ["/_**"],
|
|
529
|
-
// sources
|
|
530
|
-
sources: [],
|
|
531
|
-
excludeAppSources: []
|
|
532
|
-
},
|
|
533
|
-
async setup(config, nuxt) {
|
|
534
|
-
const { resolve } = createResolver(import.meta.url);
|
|
535
|
-
const { name, version } = await readPackageJSON(resolve("../package.json"));
|
|
536
|
-
const logger = useLogger(name);
|
|
537
|
-
logger.level = config.debug || nuxt.options.debug ? 4 : 3;
|
|
538
|
-
if (config.enabled === false) {
|
|
539
|
-
logger.debug("The module is disabled, skipping setup.");
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
config.exclude.push(`${withTrailingSlash(nuxt.options.app.buildAssetsDir)}**`);
|
|
543
|
-
nuxt.options.alias["#sitemap"] = resolve("./runtime");
|
|
544
|
-
nuxt.options.nitro.alias = nuxt.options.nitro.alias || {};
|
|
545
|
-
nuxt.options.nitro.alias["#sitemap"] = resolve("./runtime");
|
|
546
|
-
config.xslColumns = config.xslColumns || [
|
|
547
|
-
{ label: "URL", width: "50%" },
|
|
548
|
-
{ label: "Images", width: "25%", select: "count(image:image)" },
|
|
549
|
-
{
|
|
550
|
-
label: "Last Updated",
|
|
551
|
-
width: "25%",
|
|
552
|
-
select: "concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)),concat(' ', substring(sitemap:lastmod,20,6)))"
|
|
553
|
-
}
|
|
554
|
-
];
|
|
555
|
-
if (config.autoLastmod) {
|
|
556
|
-
config.defaults = config.defaults || {};
|
|
557
|
-
config.defaults.lastmod = normaliseDate(/* @__PURE__ */ new Date());
|
|
558
|
-
}
|
|
559
|
-
const normalizedSitemaps = typeof config.sitemaps === "boolean" ? {} : config.sitemaps || {};
|
|
560
|
-
if (!nuxt.options._prepare && Object.keys(normalizedSitemaps).length) {
|
|
561
|
-
const isSitemapIndexOnly = typeof normalizedSitemaps?.index !== "undefined" && Object.keys(normalizedSitemaps).length === 1;
|
|
562
|
-
if (!isSitemapIndexOnly) {
|
|
563
|
-
const warnForIgnoredKey = (key) => {
|
|
564
|
-
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.`);
|
|
565
|
-
logger.warn("Learn more at: https://nuxtseo.com/sitemap/guides/multi-sitemaps");
|
|
566
|
-
};
|
|
567
|
-
switch (true) {
|
|
568
|
-
case (config?.sources?.length || 0) > 0:
|
|
569
|
-
warnForIgnoredKey("sources");
|
|
570
|
-
break;
|
|
571
|
-
case config?.includeAppSources !== void 0:
|
|
572
|
-
warnForIgnoredKey("includeAppSources");
|
|
573
|
-
break;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
await installNuxtSiteConfig();
|
|
578
|
-
const userGlobalSources = [
|
|
579
|
-
...config.sources || []
|
|
580
|
-
];
|
|
581
|
-
const appGlobalSources = [];
|
|
582
|
-
nuxt.options.nitro.storage = nuxt.options.nitro.storage || {};
|
|
583
|
-
if (config.runtimeCacheStorage && !nuxt.options.dev && typeof config.runtimeCacheStorage === "object")
|
|
584
|
-
nuxt.options.nitro.storage.sitemap = config.runtimeCacheStorage;
|
|
585
|
-
if (!config.sitemapName.endsWith("xml")) {
|
|
586
|
-
const newName = `${config.sitemapName.split(".")[0]}.xml`;
|
|
587
|
-
logger.warn(`You have provided a \`sitemapName\` that does not end with \`.xml\`. This is not supported by search engines, renaming to \`${newName}\`.`);
|
|
588
|
-
config.sitemapName = newName;
|
|
589
|
-
}
|
|
590
|
-
config.sitemapName = withoutLeadingSlash(config.sitemapName);
|
|
591
|
-
let usingMultiSitemaps = !!config.sitemaps;
|
|
592
|
-
let isI18nMapped = false;
|
|
593
|
-
let nuxtI18nConfig = {};
|
|
594
|
-
let resolvedAutoI18n = typeof config.autoI18n === "boolean" ? false : config.autoI18n || false;
|
|
595
|
-
const hasDisabledAutoI18n = typeof config.autoI18n === "boolean" && !config.autoI18n;
|
|
596
|
-
let normalisedLocales = [];
|
|
597
|
-
let usingI18nPages = false;
|
|
598
|
-
const i18nModule = ["@nuxtjs/i18n", "nuxt-i18n-micro"].find((s) => hasNuxtModule(s));
|
|
599
|
-
if (i18nModule) {
|
|
600
|
-
const i18nVersion = await getNuxtModuleVersion(i18nModule);
|
|
601
|
-
if (i18nVersion && i18nModule === "@nuxtjs/i18n" && !await hasNuxtModuleCompatibility(i18nModule, ">=8"))
|
|
602
|
-
logger.warn(`You are using ${i18nModule} v${i18nVersion}. For the best compatibility, please upgrade to ${i18nModule} v8.0.0 or higher.`);
|
|
603
|
-
nuxtI18nConfig = await getNuxtModuleOptions(i18nModule) || {};
|
|
604
|
-
if (typeof nuxtI18nConfig.includeDefaultLocaleRoute !== "undefined") {
|
|
605
|
-
nuxtI18nConfig.strategy = nuxtI18nConfig.includeDefaultLocaleRoute ? "prefix" : "prefix_except_default";
|
|
606
|
-
}
|
|
607
|
-
normalisedLocales = normalizeLocales(nuxtI18nConfig);
|
|
608
|
-
usingI18nPages = !!Object.keys(nuxtI18nConfig.pages || {}).length;
|
|
609
|
-
if (usingI18nPages && !hasDisabledAutoI18n) {
|
|
610
|
-
const i18nPagesSources = {
|
|
611
|
-
context: {
|
|
612
|
-
name: `${i18nModule}:pages`,
|
|
613
|
-
description: "Generated from your i18n.pages config.",
|
|
614
|
-
tips: [
|
|
615
|
-
"You can disable this with `autoI18n: false`."
|
|
616
|
-
]
|
|
617
|
-
},
|
|
618
|
-
urls: []
|
|
619
|
-
};
|
|
620
|
-
for (const pageLocales of Object.values(nuxtI18nConfig?.pages)) {
|
|
621
|
-
for (const localeCode in pageLocales) {
|
|
622
|
-
const locale = normalisedLocales.find((l) => l.code === localeCode);
|
|
623
|
-
if (!locale || !pageLocales[localeCode] || pageLocales[localeCode].includes("["))
|
|
624
|
-
continue;
|
|
625
|
-
const alternatives = Object.keys(pageLocales).filter((l) => pageLocales[l] !== false).map((l) => ({
|
|
626
|
-
hreflang: normalisedLocales.find((nl) => nl.code === l)?._hreflang || l,
|
|
627
|
-
// @ts-expect-error untyped
|
|
628
|
-
href: generatePathForI18nPages({ localeCode: l, pageLocales: pageLocales[l], nuxtI18nConfig, normalisedLocales })
|
|
629
|
-
}));
|
|
630
|
-
if (alternatives.length && nuxtI18nConfig.defaultLocale && pageLocales[nuxtI18nConfig.defaultLocale] && pageLocales[nuxtI18nConfig.defaultLocale] !== false)
|
|
631
|
-
alternatives.push({ hreflang: "x-default", href: generatePathForI18nPages({ normalisedLocales, localeCode: nuxtI18nConfig.defaultLocale, pageLocales: pageLocales[nuxtI18nConfig.defaultLocale], nuxtI18nConfig }) });
|
|
632
|
-
i18nPagesSources.urls.push({
|
|
633
|
-
_sitemap: locale._sitemap,
|
|
634
|
-
loc: generatePathForI18nPages({ normalisedLocales, localeCode, pageLocales: pageLocales[localeCode], nuxtI18nConfig }),
|
|
635
|
-
alternatives
|
|
636
|
-
});
|
|
637
|
-
if (nuxtI18nConfig.strategy === "prefix_and_default" && localeCode === nuxtI18nConfig.defaultLocale) {
|
|
638
|
-
i18nPagesSources.urls.push({
|
|
639
|
-
_sitemap: locale._sitemap,
|
|
640
|
-
loc: generatePathForI18nPages({ normalisedLocales, localeCode, pageLocales: pageLocales[localeCode], nuxtI18nConfig, forcedStrategy: "prefix" }),
|
|
641
|
-
alternatives
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
appGlobalSources.push(i18nPagesSources);
|
|
647
|
-
if (Array.isArray(config.excludeAppSources))
|
|
648
|
-
config.excludeAppSources.push("nuxt:pages");
|
|
649
|
-
} else {
|
|
650
|
-
if (!normalisedLocales.length)
|
|
651
|
-
logger.warn(`You are using ${i18nModule} but have not configured any locales, this will cause issues with ${name}. Please configure \`locales\`.`);
|
|
652
|
-
}
|
|
653
|
-
const hasSetAutoI18n = typeof config.autoI18n === "object" && Object.keys(config.autoI18n).length;
|
|
654
|
-
const hasI18nConfigForAlternatives = nuxtI18nConfig.differentDomains || usingI18nPages || nuxtI18nConfig.strategy !== "no_prefix" && nuxtI18nConfig.locales;
|
|
655
|
-
if (!hasSetAutoI18n && !hasDisabledAutoI18n && hasI18nConfigForAlternatives) {
|
|
656
|
-
resolvedAutoI18n = {
|
|
657
|
-
differentDomains: nuxtI18nConfig.differentDomains,
|
|
658
|
-
defaultLocale: nuxtI18nConfig.defaultLocale,
|
|
659
|
-
locales: normalisedLocales,
|
|
660
|
-
strategy: nuxtI18nConfig.strategy,
|
|
661
|
-
// @ts-expect-error untyped
|
|
662
|
-
pages: nuxtI18nConfig.pages
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
let canI18nMap = config.sitemaps !== false && nuxtI18nConfig.strategy !== "no_prefix";
|
|
666
|
-
if (typeof config.sitemaps === "object") {
|
|
667
|
-
const isSitemapIndexOnly = typeof config.sitemaps.index !== "undefined" && Object.keys(config.sitemaps).length === 1;
|
|
668
|
-
if (!isSitemapIndexOnly)
|
|
669
|
-
canI18nMap = false;
|
|
670
|
-
}
|
|
671
|
-
if (canI18nMap && resolvedAutoI18n) {
|
|
672
|
-
config.sitemaps = { index: [...config.sitemaps?.index || [], ...config.appendSitemaps || []] };
|
|
673
|
-
for (const locale of resolvedAutoI18n.locales)
|
|
674
|
-
config.sitemaps[locale._sitemap] = { includeAppSources: true };
|
|
675
|
-
isI18nMapped = true;
|
|
676
|
-
usingMultiSitemaps = true;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
nuxt.hooks.hook("robots:config", (robotsConfig) => {
|
|
680
|
-
robotsConfig.sitemap.push(usingMultiSitemaps ? "/sitemap_index.xml" : `/${config.sitemapName}`);
|
|
681
|
-
});
|
|
682
|
-
nuxt.hooks.hook("modules:done", async () => {
|
|
683
|
-
const robotsModuleName = ["nuxt-simple-robots", "@nuxtjs/robots"].find((s) => hasNuxtModule(s));
|
|
684
|
-
let needsRobotsPolyfill = true;
|
|
685
|
-
if (robotsModuleName) {
|
|
686
|
-
const robotsVersion = await getNuxtModuleVersion(robotsModuleName);
|
|
687
|
-
if (robotsVersion && !await hasNuxtModuleCompatibility(robotsModuleName, ">=4"))
|
|
688
|
-
logger.warn(`You are using ${robotsModuleName} v${robotsVersion}. For the best compatibility, please upgrade to ${robotsModuleName} v4.0.0 or higher.`);
|
|
689
|
-
else
|
|
690
|
-
needsRobotsPolyfill = false;
|
|
691
|
-
}
|
|
692
|
-
if (needsRobotsPolyfill) {
|
|
693
|
-
nuxt.options.nitro.alias = nuxt.options.nitro.alias || {};
|
|
694
|
-
nuxt.options.nitro.alias["#internal/nuxt-robots"] = resolve("./runtime/server/robots-polyfill");
|
|
695
|
-
addServerImports([{
|
|
696
|
-
name: "getPathRobotConfig",
|
|
697
|
-
as: "getPathRobotConfig",
|
|
698
|
-
from: resolve("./runtime/server/robots-polyfill/getPathRobotConfig")
|
|
699
|
-
}]);
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
addTypeTemplate({
|
|
703
|
-
filename: "module/nuxt-sitemap.d.ts",
|
|
704
|
-
getContents: (data) => {
|
|
705
|
-
const typesPath = relative(resolve(data.nuxt.options.rootDir, data.nuxt.options.buildDir, "module"), resolve("runtime/types"));
|
|
706
|
-
const types = ` interface PrerenderRoute {
|
|
707
|
-
_sitemap?: import('${typesPath}').SitemapUrl
|
|
708
|
-
}
|
|
709
|
-
interface NitroRouteRules {
|
|
710
|
-
index?: boolean
|
|
711
|
-
sitemap?: import('${typesPath}').SitemapItemDefaults
|
|
712
|
-
}
|
|
713
|
-
interface NitroRouteConfig {
|
|
714
|
-
index?: boolean
|
|
715
|
-
sitemap?: import('${typesPath}').SitemapItemDefaults
|
|
716
|
-
}
|
|
717
|
-
interface NitroRuntimeHooks {
|
|
718
|
-
'sitemap:index-resolved': (ctx: import('${typesPath}').SitemapIndexRenderCtx) => void | Promise<void>
|
|
719
|
-
'sitemap:input': (ctx: import('${typesPath}').SitemapInputCtx) => void | Promise<void>
|
|
720
|
-
'sitemap:resolved': (ctx: import('${typesPath}').SitemapRenderCtx) => void | Promise<void>
|
|
721
|
-
'sitemap:output': (ctx: import('${typesPath}').SitemapOutputHookCtx) => void | Promise<void>
|
|
722
|
-
'sitemap:sources': (ctx: import('${typesPath}').SitemapSourcesHookCtx) => void | Promise<void>
|
|
723
|
-
}`;
|
|
724
|
-
return `// Generated by nuxt-robots
|
|
725
|
-
declare module 'nitropack' {
|
|
726
|
-
${types}
|
|
727
|
-
}
|
|
728
|
-
declare module 'nitropack/types' {
|
|
729
|
-
${types}
|
|
730
|
-
}
|
|
731
|
-
declare module 'vue-router' {
|
|
732
|
-
interface RouteMeta {
|
|
733
|
-
sitemap?: import('${typesPath}').SitemapItemDefaults
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
export {}
|
|
738
|
-
`;
|
|
739
|
-
}
|
|
740
|
-
}, {
|
|
741
|
-
nitro: true,
|
|
742
|
-
nuxt: true
|
|
743
|
-
});
|
|
744
|
-
const prerenderedRoutes = nuxt.options.nitro.prerender?.routes || [];
|
|
745
|
-
const prerenderSitemap = isNuxtGenerate() || includesSitemapRoot(config.sitemapName, prerenderedRoutes);
|
|
746
|
-
const routeRules = {};
|
|
747
|
-
nuxt.options.nitro.routeRules = nuxt.options.nitro.routeRules || {};
|
|
748
|
-
if (prerenderSitemap) {
|
|
749
|
-
routeRules.headers = {
|
|
750
|
-
"Content-Type": "text/xml; charset=UTF-8",
|
|
751
|
-
"Cache-Control": config.cacheMaxAgeSeconds ? `public, max-age=${config.cacheMaxAgeSeconds}, must-revalidate` : "no-cache, no-store",
|
|
752
|
-
"X-Sitemap-Prerendered": (/* @__PURE__ */ new Date()).toISOString()
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
if (config.xsl) {
|
|
756
|
-
nuxt.options.nitro.routeRules[config.xsl] = {
|
|
757
|
-
headers: {
|
|
758
|
-
"Content-Type": "application/xslt+xml"
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
if (usingMultiSitemaps) {
|
|
763
|
-
nuxt.options.nitro.routeRules["/sitemap.xml"] = { redirect: "/sitemap_index.xml" };
|
|
764
|
-
nuxt.options.nitro.routeRules["/sitemap_index.xml"] = routeRules;
|
|
765
|
-
if (typeof config.sitemaps === "object") {
|
|
766
|
-
for (const k in config.sitemaps) {
|
|
767
|
-
if (k === "index")
|
|
768
|
-
continue;
|
|
769
|
-
nuxt.options.nitro.routeRules[joinURL(config.sitemapsPathPrefix || "", `/${k}.xml`)] = routeRules;
|
|
770
|
-
const sitemapConfig = config.sitemaps[k];
|
|
771
|
-
if (sitemapConfig.chunks) {
|
|
772
|
-
nuxt.options.nitro.routeRules[joinURL(config.sitemapsPathPrefix || "", `/${k}-*.xml`)] = routeRules;
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
} else {
|
|
776
|
-
nuxt.options.nitro.routeRules[joinURL(config.sitemapsPathPrefix || "", `/[0-9]+.xml`)] = routeRules;
|
|
777
|
-
}
|
|
778
|
-
} else {
|
|
779
|
-
nuxt.options.nitro.routeRules[`/${config.sitemapName}`] = routeRules;
|
|
780
|
-
}
|
|
781
|
-
if (config.experimentalWarmUp)
|
|
782
|
-
addServerPlugin(resolve("./runtime/server/plugins/warm-up"));
|
|
783
|
-
if (config.experimentalCompression)
|
|
784
|
-
addServerPlugin(resolve("./runtime/server/plugins/compression"));
|
|
785
|
-
const isNuxtContentDocumentDriven = !!nuxt.options.content?.documentDriven || config.strictNuxtContentPaths;
|
|
786
|
-
const usingNuxtContent = hasNuxtModule("@nuxt/content");
|
|
787
|
-
const isNuxtContentV3 = usingNuxtContent && await hasNuxtModuleCompatibility("@nuxt/content", "^3");
|
|
788
|
-
const nuxtV3Collections = /* @__PURE__ */ new Set();
|
|
789
|
-
const isNuxtContentV2 = usingNuxtContent && await hasNuxtModuleCompatibility("@nuxt/content", "^2");
|
|
790
|
-
if (isNuxtContentV3) {
|
|
791
|
-
if (nuxt.options._installedModules.some((m) => m.meta.name === "Content")) {
|
|
792
|
-
logger.warn("You have loaded `@nuxt/content` before `@nuxtjs/sitemap`, this may cause issues with the integration. Please ensure `@nuxtjs/sitemap` is loaded first.");
|
|
793
|
-
}
|
|
794
|
-
config.exclude.push("/__nuxt_content/**");
|
|
795
|
-
const needsCustomAlias = await hasNuxtModuleCompatibility("@nuxt/content", "<3.6.0");
|
|
796
|
-
if (needsCustomAlias) {
|
|
797
|
-
nuxt.options.alias["#sitemap/content-v3-nitro-path"] = resolve(dirname(resolveModule("@nuxt/content")), "runtime/nitro");
|
|
798
|
-
nuxt.options.alias["@nuxt/content/nitro"] = resolve("./runtime/server/content-compat");
|
|
799
|
-
}
|
|
800
|
-
nuxt.hooks.hook("content:file:afterParse", (ctx) => {
|
|
801
|
-
const content = ctx.content;
|
|
802
|
-
nuxtV3Collections.add(ctx.collection.name);
|
|
803
|
-
if (String(ctx.content.path).includes("/.")) {
|
|
804
|
-
ctx.content.sitemap = null;
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
if (!("sitemap" in ctx.collection.fields)) {
|
|
808
|
-
ctx.content.sitemap = null;
|
|
809
|
-
return;
|
|
810
|
-
}
|
|
811
|
-
if (typeof content.sitemap !== "undefined" && !content.sitemap) {
|
|
812
|
-
ctx.content.sitemap = null;
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
if (ctx.content.robots === false) {
|
|
816
|
-
ctx.content.sitemap = null;
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
const images = [];
|
|
820
|
-
if (config.discoverImages) {
|
|
821
|
-
images.push(
|
|
822
|
-
...content.body.value?.filter(
|
|
823
|
-
(c) => ["image", "img", "nuxtimg", "nuxt-img"].includes(c[0])
|
|
824
|
-
).filter((c) => c[1]?.src).map((c) => ({ loc: c[1].src })) || []
|
|
825
|
-
);
|
|
826
|
-
}
|
|
827
|
-
const lastmod = content.seo?.articleModifiedTime || content.updatedAt;
|
|
828
|
-
const defaults = {
|
|
829
|
-
loc: content.path
|
|
830
|
-
};
|
|
831
|
-
if (images.length > 0)
|
|
832
|
-
defaults.images = images;
|
|
833
|
-
if (lastmod)
|
|
834
|
-
defaults.lastmod = lastmod;
|
|
835
|
-
ctx.content.sitemap = defu(typeof content.sitemap === "object" ? content.sitemap : {}, defaults);
|
|
836
|
-
});
|
|
837
|
-
addServerHandler({
|
|
838
|
-
route: "/__sitemap__/nuxt-content-urls.json",
|
|
839
|
-
handler: resolve("./runtime/server/routes/__sitemap__/nuxt-content-urls-v3")
|
|
840
|
-
});
|
|
841
|
-
if (config.strictNuxtContentPaths) {
|
|
842
|
-
logger.warn("You have set `strictNuxtContentPaths: true` but are using @nuxt/content v3. This is not required, please remove it.");
|
|
843
|
-
}
|
|
844
|
-
appGlobalSources.push({
|
|
845
|
-
context: {
|
|
846
|
-
name: "@nuxt/content@v3:urls",
|
|
847
|
-
description: "Generated from your markdown files.",
|
|
848
|
-
tips: [`Parsing the following collections: ${Array.from(nuxtV3Collections).join(", ")}`]
|
|
849
|
-
},
|
|
850
|
-
fetch: "/__sitemap__/nuxt-content-urls.json"
|
|
851
|
-
});
|
|
852
|
-
} else if (isNuxtContentV2) {
|
|
853
|
-
addServerPlugin(resolve("./runtime/server/plugins/nuxt-content-v2"));
|
|
854
|
-
addServerHandler({
|
|
855
|
-
route: "/__sitemap__/nuxt-content-urls.json",
|
|
856
|
-
handler: resolve("./runtime/server/routes/__sitemap__/nuxt-content-urls-v2")
|
|
857
|
-
});
|
|
858
|
-
const tips = [];
|
|
859
|
-
if (nuxt.options.content?.documentDriven)
|
|
860
|
-
tips.push("Enabled because you're using `@nuxt/content` with `documentDriven: true`.");
|
|
861
|
-
else if (config.strictNuxtContentPaths)
|
|
862
|
-
tips.push("Enabled because you've set `config.strictNuxtContentPaths: true`.");
|
|
863
|
-
else
|
|
864
|
-
tips.push("You can provide a `sitemap` key in your markdown frontmatter to configure specific URLs. Make sure you include a `loc`.");
|
|
865
|
-
appGlobalSources.push({
|
|
866
|
-
context: {
|
|
867
|
-
name: "@nuxt/content@v2:urls",
|
|
868
|
-
description: "Generated from your markdown files.",
|
|
869
|
-
tips
|
|
870
|
-
},
|
|
871
|
-
fetch: "/__sitemap__/nuxt-content-urls.json"
|
|
872
|
-
});
|
|
873
|
-
}
|
|
874
|
-
const sitemaps = {};
|
|
875
|
-
if (usingMultiSitemaps) {
|
|
876
|
-
addServerHandler({
|
|
877
|
-
route: "/sitemap_index.xml",
|
|
878
|
-
handler: resolve("./runtime/server/routes/sitemap_index.xml"),
|
|
879
|
-
lazy: true,
|
|
880
|
-
middleware: false
|
|
881
|
-
});
|
|
882
|
-
if (config.sitemapsPathPrefix && config.sitemapsPathPrefix !== "/") {
|
|
883
|
-
addServerHandler({
|
|
884
|
-
route: joinURL(config.sitemapsPathPrefix, `/**:sitemap`),
|
|
885
|
-
handler: resolve("./runtime/server/routes/sitemap/[sitemap].xml"),
|
|
886
|
-
lazy: true,
|
|
887
|
-
middleware: false
|
|
888
|
-
});
|
|
889
|
-
} else {
|
|
890
|
-
const sitemapNames = Object.keys(config.sitemaps || {});
|
|
891
|
-
for (const sitemapName of sitemapNames) {
|
|
892
|
-
if (sitemapName === "index")
|
|
893
|
-
continue;
|
|
894
|
-
const sitemapConfig = config.sitemaps[sitemapName];
|
|
895
|
-
addServerHandler({
|
|
896
|
-
route: withLeadingSlash(`${sitemapName}.xml`),
|
|
897
|
-
handler: resolve("./runtime/server/routes/sitemap/[sitemap].xml"),
|
|
898
|
-
lazy: true,
|
|
899
|
-
middleware: false
|
|
900
|
-
});
|
|
901
|
-
if (sitemapConfig.chunks) {
|
|
902
|
-
addServerHandler({
|
|
903
|
-
route: `/${sitemapName}-*.xml`,
|
|
904
|
-
handler: resolve("./runtime/server/routes/sitemap/[sitemap].xml"),
|
|
905
|
-
lazy: true,
|
|
906
|
-
middleware: false
|
|
907
|
-
});
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
sitemaps.index = {
|
|
912
|
-
sitemapName: "index",
|
|
913
|
-
_route: withBase("sitemap_index.xml", nuxt.options.app.baseURL || "/"),
|
|
914
|
-
// @ts-expect-error untyped
|
|
915
|
-
sitemaps: [...config.sitemaps.index || [], ...config.appendSitemaps || []]
|
|
916
|
-
};
|
|
917
|
-
if (typeof config.sitemaps === "object") {
|
|
918
|
-
for (const sitemapName in config.sitemaps) {
|
|
919
|
-
if (sitemapName === "index")
|
|
920
|
-
continue;
|
|
921
|
-
const definition = config.sitemaps[sitemapName];
|
|
922
|
-
const sitemapConfig = defu(
|
|
923
|
-
{
|
|
924
|
-
sitemapName,
|
|
925
|
-
_route: withBase(joinURL(config.sitemapsPathPrefix || "", `${sitemapName}.xml`), nuxt.options.app.baseURL || "/"),
|
|
926
|
-
_hasSourceChunk: typeof definition.urls !== "undefined" || definition.sources?.length
|
|
927
|
-
},
|
|
928
|
-
{ ...definition, urls: void 0, sources: void 0 },
|
|
929
|
-
{ include: config.include, exclude: config.exclude }
|
|
930
|
-
);
|
|
931
|
-
if (definition.chunks) {
|
|
932
|
-
let chunkSize = config.defaultSitemapsChunkSize || 1e3;
|
|
933
|
-
if (typeof definition.chunks === "number") {
|
|
934
|
-
if (definition.chunks <= 0) {
|
|
935
|
-
logger.warn(`Invalid chunks value (${definition.chunks}) for sitemap "${sitemapName}". Using default.`);
|
|
936
|
-
} else {
|
|
937
|
-
chunkSize = definition.chunks;
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
if (definition.chunkSize !== void 0) {
|
|
941
|
-
if (typeof definition.chunkSize !== "number" || definition.chunkSize <= 0) {
|
|
942
|
-
logger.warn(`Invalid chunkSize value (${definition.chunkSize}) for sitemap "${sitemapName}". Using default.`);
|
|
943
|
-
} else {
|
|
944
|
-
chunkSize = definition.chunkSize;
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
sitemapConfig._isChunking = true;
|
|
948
|
-
sitemapConfig._chunkSize = chunkSize;
|
|
949
|
-
sitemapConfig.chunks = definition.chunks;
|
|
950
|
-
sitemapConfig.chunkSize = definition.chunkSize;
|
|
951
|
-
}
|
|
952
|
-
sitemaps[sitemapName] = sitemapConfig;
|
|
953
|
-
}
|
|
954
|
-
} else {
|
|
955
|
-
sitemaps.chunks = {
|
|
956
|
-
sitemapName: "chunks",
|
|
957
|
-
defaults: config.defaults,
|
|
958
|
-
include: config.include,
|
|
959
|
-
exclude: config.exclude,
|
|
960
|
-
includeAppSources: true
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
} else {
|
|
964
|
-
sitemaps[config.sitemapName] = {
|
|
965
|
-
sitemapName: config.sitemapName,
|
|
966
|
-
route: withBase(config.sitemapName, nuxt.options.app.baseURL || "/"),
|
|
967
|
-
// will contain the xml
|
|
968
|
-
defaults: config.defaults,
|
|
969
|
-
include: config.include,
|
|
970
|
-
exclude: config.exclude,
|
|
971
|
-
includeAppSources: true
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
if (resolvedAutoI18n && usingI18nPages && !hasDisabledAutoI18n) {
|
|
975
|
-
const pages = nuxtI18nConfig?.pages || {};
|
|
976
|
-
for (const sitemapName in sitemaps) {
|
|
977
|
-
let mapToI18nPages = function(path) {
|
|
978
|
-
if (typeof path !== "string")
|
|
979
|
-
return [path];
|
|
980
|
-
const withoutSlashes = withoutTrailingSlash(withoutLeadingSlash(path)).replace("/index", "");
|
|
981
|
-
if (pages && withoutSlashes in pages) {
|
|
982
|
-
const pageLocales = pages[withoutSlashes];
|
|
983
|
-
if (pageLocales) {
|
|
984
|
-
return Object.keys(pageLocales).map((localeCode) => withLeadingSlash(generatePathForI18nPages({
|
|
985
|
-
localeCode,
|
|
986
|
-
pageLocales: pageLocales[localeCode],
|
|
987
|
-
nuxtI18nConfig,
|
|
988
|
-
normalisedLocales
|
|
989
|
-
})));
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
let match = [path];
|
|
993
|
-
Object.values(pages).forEach((pageLocales) => {
|
|
994
|
-
if (pageLocales && nuxtI18nConfig.defaultLocale in pageLocales && pageLocales[nuxtI18nConfig.defaultLocale] === path)
|
|
995
|
-
match = Object.keys(pageLocales).map((localeCode) => withLeadingSlash(generatePathForI18nPages({ localeCode, pageLocales: pageLocales[localeCode], nuxtI18nConfig, normalisedLocales })));
|
|
996
|
-
});
|
|
997
|
-
return match;
|
|
998
|
-
};
|
|
999
|
-
if (["index", "chunks"].includes(sitemapName))
|
|
1000
|
-
continue;
|
|
1001
|
-
const sitemap = sitemaps[sitemapName];
|
|
1002
|
-
sitemap.include = (sitemap.include || []).flatMap((path) => mapToI18nPages(path));
|
|
1003
|
-
sitemap.exclude = (sitemap.exclude || []).flatMap((path) => mapToI18nPages(path));
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
if (resolvedAutoI18n && resolvedAutoI18n.locales && resolvedAutoI18n.strategy !== "no_prefix") {
|
|
1007
|
-
const i18n = resolvedAutoI18n;
|
|
1008
|
-
for (const sitemapName in sitemaps) {
|
|
1009
|
-
if (["index", "chunks"].includes(sitemapName))
|
|
1010
|
-
continue;
|
|
1011
|
-
const sitemap = sitemaps[sitemapName];
|
|
1012
|
-
sitemap.include = (sitemap.include || []).map((path) => splitPathForI18nLocales(path, i18n)).flat();
|
|
1013
|
-
sitemap.exclude = (sitemap.exclude || []).map((path) => splitPathForI18nLocales(path, i18n)).flat();
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
for (const sitemapName in sitemaps) {
|
|
1017
|
-
const sitemap = sitemaps[sitemapName];
|
|
1018
|
-
sitemap.include = normalizeFilters(sitemap.include);
|
|
1019
|
-
sitemap.exclude = normalizeFilters(sitemap.exclude);
|
|
1020
|
-
}
|
|
1021
|
-
const runtimeConfig = {
|
|
1022
|
-
isI18nMapped,
|
|
1023
|
-
sitemapName: config.sitemapName,
|
|
1024
|
-
isMultiSitemap: usingMultiSitemaps,
|
|
1025
|
-
excludeAppSources: config.excludeAppSources,
|
|
1026
|
-
cacheMaxAgeSeconds: nuxt.options.dev ? 0 : config.cacheMaxAgeSeconds,
|
|
1027
|
-
autoLastmod: config.autoLastmod,
|
|
1028
|
-
defaultSitemapsChunkSize: config.defaultSitemapsChunkSize,
|
|
1029
|
-
minify: config.minify,
|
|
1030
|
-
sortEntries: config.sortEntries,
|
|
1031
|
-
debug: config.debug,
|
|
1032
|
-
// needed for nuxt/content integration and prerendering
|
|
1033
|
-
discoverImages: config.discoverImages,
|
|
1034
|
-
discoverVideos: config.discoverVideos,
|
|
1035
|
-
sitemapsPathPrefix: config.sitemapsPathPrefix,
|
|
1036
|
-
/* @nuxt/content */
|
|
1037
|
-
isNuxtContentDocumentDriven,
|
|
1038
|
-
/* xsl styling */
|
|
1039
|
-
xsl: config.xsl,
|
|
1040
|
-
xslTips: config.xslTips,
|
|
1041
|
-
xslColumns: config.xslColumns,
|
|
1042
|
-
credits: config.credits,
|
|
1043
|
-
version,
|
|
1044
|
-
sitemaps
|
|
1045
|
-
};
|
|
1046
|
-
if (resolvedAutoI18n)
|
|
1047
|
-
runtimeConfig.autoI18n = resolvedAutoI18n;
|
|
1048
|
-
nuxt.options.runtimeConfig.sitemap = runtimeConfig;
|
|
1049
|
-
if (config.debug || nuxt.options.dev) {
|
|
1050
|
-
addServerHandler({
|
|
1051
|
-
route: "/__sitemap__/debug.json",
|
|
1052
|
-
handler: resolve("./runtime/server/routes/__sitemap__/debug")
|
|
1053
|
-
});
|
|
1054
|
-
if (usingMultiSitemaps) {
|
|
1055
|
-
addServerHandler({
|
|
1056
|
-
route: "/__sitemap__/**:sitemap",
|
|
1057
|
-
handler: resolve("./runtime/server/routes/sitemap/[sitemap].xml"),
|
|
1058
|
-
lazy: true,
|
|
1059
|
-
middleware: true
|
|
1060
|
-
});
|
|
1061
|
-
}
|
|
1062
|
-
setupDevToolsUI(config, resolve);
|
|
1063
|
-
}
|
|
1064
|
-
const imports = [
|
|
1065
|
-
{
|
|
1066
|
-
from: resolve("./runtime/server/composables/defineSitemapEventHandler"),
|
|
1067
|
-
name: "defineSitemapEventHandler"
|
|
1068
|
-
},
|
|
1069
|
-
{
|
|
1070
|
-
from: resolve("./runtime/server/composables/asSitemapUrl"),
|
|
1071
|
-
name: "asSitemapUrl"
|
|
1072
|
-
}
|
|
1073
|
-
];
|
|
1074
|
-
addServerImports(imports);
|
|
1075
|
-
const pagesPromise = createPagesPromise();
|
|
1076
|
-
const nitroPromise = createNitroPromise();
|
|
1077
|
-
let resolvedConfigUrls = false;
|
|
1078
|
-
nuxt.hooks.hook("nitro:config", (nitroConfig) => {
|
|
1079
|
-
nitroConfig.virtual["#sitemap-virtual/global-sources.mjs"] = async () => {
|
|
1080
|
-
const { prerenderUrls, routeRules: routeRules2 } = generateExtraRoutesFromNuxtConfig();
|
|
1081
|
-
const prerenderUrlsFinal = [
|
|
1082
|
-
...prerenderUrls,
|
|
1083
|
-
...((await nitroPromise)._prerenderedRoutes || []).filter((r) => {
|
|
1084
|
-
if (["/200.html", "/404.html", "/index.html"].includes(r.route) || r.error || isPathFile(r.route))
|
|
1085
|
-
return false;
|
|
1086
|
-
return r.contentType?.includes("text/html");
|
|
1087
|
-
}).map((r) => r._sitemap)
|
|
1088
|
-
];
|
|
1089
|
-
const pageSource = convertNuxtPagesToSitemapEntries(await pagesPromise, {
|
|
1090
|
-
isI18nMapped,
|
|
1091
|
-
autoLastmod: config.autoLastmod,
|
|
1092
|
-
defaultLocale: nuxtI18nConfig.defaultLocale || "en",
|
|
1093
|
-
strategy: nuxtI18nConfig.strategy || "no_prefix",
|
|
1094
|
-
routesNameSeparator: nuxtI18nConfig.routesNameSeparator,
|
|
1095
|
-
normalisedLocales,
|
|
1096
|
-
filter: {
|
|
1097
|
-
include: normalizeFilters(config.include),
|
|
1098
|
-
exclude: normalizeFilters(config.exclude)
|
|
1099
|
-
},
|
|
1100
|
-
isI18nMicro: i18nModule === "nuxt-i18n-micro"
|
|
1101
|
-
});
|
|
1102
|
-
if (!pageSource.length) {
|
|
1103
|
-
pageSource.push(nuxt.options.app.baseURL || "/");
|
|
1104
|
-
}
|
|
1105
|
-
if (!resolvedConfigUrls && config.urls) {
|
|
1106
|
-
if (config.urls) {
|
|
1107
|
-
userGlobalSources.push({
|
|
1108
|
-
context: {
|
|
1109
|
-
name: "sitemap:urls",
|
|
1110
|
-
description: "Set with the `sitemap.urls` config."
|
|
1111
|
-
},
|
|
1112
|
-
urls: await resolveUrls(config.urls, { path: "sitemap:urls", logger })
|
|
1113
|
-
});
|
|
1114
|
-
}
|
|
1115
|
-
resolvedConfigUrls = true;
|
|
1116
|
-
}
|
|
1117
|
-
const globalSources = [
|
|
1118
|
-
...userGlobalSources.map((s) => {
|
|
1119
|
-
if (typeof s === "string" || Array.isArray(s)) {
|
|
1120
|
-
return {
|
|
1121
|
-
sourceType: "user",
|
|
1122
|
-
fetch: s
|
|
1123
|
-
};
|
|
1124
|
-
}
|
|
1125
|
-
s.sourceType = "user";
|
|
1126
|
-
return s;
|
|
1127
|
-
}),
|
|
1128
|
-
...(config.excludeAppSources === true ? [] : [
|
|
1129
|
-
...appGlobalSources,
|
|
1130
|
-
{
|
|
1131
|
-
context: {
|
|
1132
|
-
name: "nuxt:pages",
|
|
1133
|
-
description: "Generated from your static page files.",
|
|
1134
|
-
tips: [
|
|
1135
|
-
"Can be disabled with `{ excludeAppSources: ['nuxt:pages'] }`."
|
|
1136
|
-
]
|
|
1137
|
-
},
|
|
1138
|
-
urls: pageSource
|
|
1139
|
-
},
|
|
1140
|
-
{
|
|
1141
|
-
context: {
|
|
1142
|
-
name: "nuxt:route-rules",
|
|
1143
|
-
description: "Generated from your route rules config.",
|
|
1144
|
-
tips: [
|
|
1145
|
-
"Can be disabled with `{ excludeAppSources: ['nuxt:route-rules'] }`."
|
|
1146
|
-
]
|
|
1147
|
-
},
|
|
1148
|
-
urls: routeRules2
|
|
1149
|
-
},
|
|
1150
|
-
{
|
|
1151
|
-
context: {
|
|
1152
|
-
name: "nuxt:prerender",
|
|
1153
|
-
description: "Generated at build time when prerendering.",
|
|
1154
|
-
tips: [
|
|
1155
|
-
"Can be disabled with `{ excludeAppSources: ['nuxt:prerender'] }`."
|
|
1156
|
-
]
|
|
1157
|
-
},
|
|
1158
|
-
urls: prerenderUrlsFinal
|
|
1159
|
-
}
|
|
1160
|
-
]).filter((s) => !config.excludeAppSources.includes(s.context.name) && (!!s.urls?.length || !!s.fetch)).map((s) => {
|
|
1161
|
-
s.sourceType = "app";
|
|
1162
|
-
return s;
|
|
1163
|
-
})
|
|
1164
|
-
];
|
|
1165
|
-
return `export const sources = ${JSON.stringify(globalSources, null, 4)}`;
|
|
1166
|
-
};
|
|
1167
|
-
const extraSitemapModules = typeof config.sitemaps == "object" ? Object.keys(config.sitemaps).filter((n) => n !== "index") : [];
|
|
1168
|
-
const sitemapSources = {};
|
|
1169
|
-
nitroConfig.virtual[`#sitemap-virtual/child-sources.mjs`] = async () => {
|
|
1170
|
-
for (const sitemapName of extraSitemapModules) {
|
|
1171
|
-
sitemapSources[sitemapName] = sitemapSources[sitemapName] || [];
|
|
1172
|
-
const definition = config.sitemaps[sitemapName];
|
|
1173
|
-
if (!sitemapSources[sitemapName].length) {
|
|
1174
|
-
if (definition.urls) {
|
|
1175
|
-
sitemapSources[sitemapName].push({
|
|
1176
|
-
context: {
|
|
1177
|
-
name: `sitemaps:${sitemapName}:urls`,
|
|
1178
|
-
description: "Set with the `sitemap.urls` config."
|
|
1179
|
-
},
|
|
1180
|
-
urls: await resolveUrls(definition.urls, { path: `sitemaps:${sitemapName}:urls`, logger })
|
|
1181
|
-
});
|
|
1182
|
-
}
|
|
1183
|
-
sitemapSources[sitemapName].push(
|
|
1184
|
-
...(definition.sources || []).map((s) => {
|
|
1185
|
-
if (typeof s === "string" || Array.isArray(s)) {
|
|
1186
|
-
return {
|
|
1187
|
-
sourceType: "user",
|
|
1188
|
-
fetch: s
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
s.sourceType = "user";
|
|
1192
|
-
return s;
|
|
1193
|
-
})
|
|
1194
|
-
);
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
return `export const sources = ${JSON.stringify(sitemapSources, null, 4)}`;
|
|
1198
|
-
};
|
|
1199
|
-
});
|
|
1200
|
-
if (config.xsl === "/__sitemap__/style.xsl") {
|
|
1201
|
-
addServerHandler({
|
|
1202
|
-
route: config.xsl,
|
|
1203
|
-
handler: resolve("./runtime/server/routes/sitemap.xsl")
|
|
1204
|
-
});
|
|
1205
|
-
config.xsl = withBase(config.xsl, nuxt.options.app.baseURL);
|
|
1206
|
-
if (prerenderSitemap)
|
|
1207
|
-
addPrerenderRoutes(config.xsl);
|
|
1208
|
-
}
|
|
1209
|
-
addServerHandler({
|
|
1210
|
-
route: `/${config.sitemapName}`,
|
|
1211
|
-
handler: resolve("./runtime/server/routes/sitemap.xml")
|
|
1212
|
-
});
|
|
1213
|
-
setupPrerenderHandler({ runtimeConfig, logger });
|
|
1214
|
-
}
|
|
1215
|
-
});
|
|
1216
|
-
|
|
1217
|
-
export { module as default };
|