@nuxtjs/sitemap 7.4.7 → 7.4.9
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/README.md +1 -1
- package/dist/client/200.html +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/Cu_iTDKX.js +157 -0
- package/dist/client/_nuxt/QpeyiL4d.js +1 -0
- package/dist/client/_nuxt/SKYDSeR3.js +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/bafd23ec-aaa0-4756-a4c4-11462568906c.json +1 -0
- package/dist/client/_nuxt/{entry.D5V0t8Hh.css → entry.Ci1pP-eR.css} +1 -1
- package/dist/client/_nuxt/error-404.CqOOUcXJ.css +1 -0
- package/dist/client/_nuxt/error-500.jRvomCfk.css +1 -0
- package/dist/client/index.html +1 -1
- package/dist/client/sitemap.xml +1 -1
- package/dist/content.d.mts +36 -37
- package/dist/content.d.ts +36 -37
- package/dist/content.mjs +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +202 -149
- package/dist/runtime/server/plugins/compression.d.ts +1 -1
- package/dist/runtime/server/plugins/nuxt-content-v2.d.ts +1 -1
- package/dist/runtime/server/plugins/warm-up.d.ts +1 -1
- package/dist/runtime/server/routes/__sitemap__/debug.d.ts +5 -0
- package/dist/runtime/server/routes/__sitemap__/debug.js +5 -3
- package/dist/runtime/server/sitemap/builder/sitemap.js +6 -1
- package/dist/runtime/server/sitemap/urlset/sources.js +20 -4
- package/dist/runtime/types.d.ts +2 -2
- package/dist/shared/{sitemap.DR3_6qqU.mjs → sitemap.Bj0OAEtK.mjs} +12 -1
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.mjs +1 -1
- package/package.json +34 -26
- package/virtual.d.ts +4 -0
- package/dist/client/_nuxt/CVMmb_pX.js +0 -1
- package/dist/client/_nuxt/Uwg2rjhu.js +0 -172
- package/dist/client/_nuxt/builds/meta/d2f0f6ff-dbbc-45cd-bac8-0f24a0d6c572.json +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/module.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { provider, env } from 'std-env';
|
|
|
10
10
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
11
11
|
import { join } from 'node:path';
|
|
12
12
|
import chalk from 'chalk';
|
|
13
|
-
import { p as parseHtmlExtractSitemapMeta } from './shared/sitemap.
|
|
13
|
+
import { p as parseHtmlExtractSitemapMeta } from './shared/sitemap.Bj0OAEtK.mjs';
|
|
14
14
|
import { normaliseDate } from '../dist/runtime/server/sitemap/urlset/normalise.js';
|
|
15
15
|
import { isPathFile } from 'nuxt-site-config/urls';
|
|
16
16
|
import 'ultrahtml';
|
|
@@ -46,7 +46,7 @@ function deepForEachPage(pages, callback, opts, fullpath = null, depth = 0) {
|
|
|
46
46
|
if (opts.isI18nMicro) {
|
|
47
47
|
const localePattern = /\/:locale\(([^)]+)\)/;
|
|
48
48
|
const match = localePattern.exec(currentPath || "");
|
|
49
|
-
if (match) {
|
|
49
|
+
if (match && match[1]) {
|
|
50
50
|
const locales = match[1].split("|");
|
|
51
51
|
locales.forEach((locale) => {
|
|
52
52
|
const subPage = { ...page };
|
|
@@ -99,12 +99,9 @@ function convertNuxtPagesToSitemapEntries(pages, config) {
|
|
|
99
99
|
}
|
|
100
100
|
const pagesWithMeta = flattenedPages.map((p) => {
|
|
101
101
|
if (config.autoLastmod && p.page.file) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
p.lastmod = stats.mtime;
|
|
106
|
-
} catch {
|
|
107
|
-
}
|
|
102
|
+
const stats = statSync(p.page.file, { throwIfNoEntry: false });
|
|
103
|
+
if (stats?.mtime)
|
|
104
|
+
p.lastmod = stats.mtime;
|
|
108
105
|
}
|
|
109
106
|
if (p.page?.meta?.sitemap) {
|
|
110
107
|
p = defu(p.page.meta.sitemap, p);
|
|
@@ -115,6 +112,8 @@ function convertNuxtPagesToSitemapEntries(pages, config) {
|
|
|
115
112
|
pagesWithMeta.reduce((acc, e) => {
|
|
116
113
|
if (e.page.name?.includes(routesNameSeparator)) {
|
|
117
114
|
const [name, locale] = e.page.name.split(routesNameSeparator);
|
|
115
|
+
if (!name)
|
|
116
|
+
return acc;
|
|
118
117
|
if (!acc[name])
|
|
119
118
|
acc[name] = [];
|
|
120
119
|
const { _sitemap } = config.normalisedLocales.find((l) => l.code === locale) || { _sitemap: locale };
|
|
@@ -129,6 +128,8 @@ function convertNuxtPagesToSitemapEntries(pages, config) {
|
|
|
129
128
|
if (locale === "default") {
|
|
130
129
|
return entries.map((e) => {
|
|
131
130
|
const [name] = (e.page?.name || "").split(routesNameSeparator);
|
|
131
|
+
if (!name)
|
|
132
|
+
return false;
|
|
132
133
|
if (localeGroups[name]?.some((a) => a.locale === config.defaultLocale))
|
|
133
134
|
return false;
|
|
134
135
|
const defaultLocale = config.normalisedLocales.find((l) => l.code === config.defaultLocale);
|
|
@@ -271,7 +272,7 @@ function isNuxtGenerate(nuxt = useNuxt()) {
|
|
|
271
272
|
}
|
|
272
273
|
const NuxtRedirectHtmlRegex = /<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=([^"]+)"><\/head><\/html>/;
|
|
273
274
|
function setupPrerenderHandler(_options, nuxt = useNuxt()) {
|
|
274
|
-
const { runtimeConfig: options, logger } = _options;
|
|
275
|
+
const { runtimeConfig: options, logger, generateGlobalSources, generateChildSources } = _options;
|
|
275
276
|
const prerenderedRoutes = nuxt.options.nitro.prerender?.routes || [];
|
|
276
277
|
let prerenderSitemap = isNuxtGenerate() || includesSitemapRoot(options.sitemapName, prerenderedRoutes);
|
|
277
278
|
if (resolveNitroPreset() === "vercel-edge") {
|
|
@@ -289,11 +290,24 @@ function setupPrerenderHandler(_options, nuxt = useNuxt()) {
|
|
|
289
290
|
return;
|
|
290
291
|
}
|
|
291
292
|
nuxt.options.nitro.prerender.routes = nuxt.options.nitro.prerender.routes.filter((r) => r && !includesSitemapRoot(options.sitemapName, [r]));
|
|
293
|
+
const runtimeAssetsPath = join(nuxt.options.rootDir, "node_modules/.cache/nuxt/sitemap");
|
|
294
|
+
nuxt.hooks.hook("nitro:config", (nitroConfig) => {
|
|
295
|
+
nitroConfig.virtual = nitroConfig.virtual || {};
|
|
296
|
+
nitroConfig.virtual["#sitemap-virtual/read-sources.mjs"] = `
|
|
297
|
+
import { readFile } from 'node:fs/promises'
|
|
298
|
+
import { join } from 'pathe'
|
|
299
|
+
|
|
300
|
+
export async function readSourcesFromFilesystem(filename) {
|
|
301
|
+
if (!import.meta.prerender) {
|
|
302
|
+
return null
|
|
303
|
+
}
|
|
304
|
+
const path = join(${JSON.stringify(runtimeAssetsPath)}, filename)
|
|
305
|
+
const data = await readFile(path, 'utf-8').catch(() => null)
|
|
306
|
+
return data ? JSON.parse(data) : null
|
|
307
|
+
}
|
|
308
|
+
`;
|
|
309
|
+
});
|
|
292
310
|
nuxt.hooks.hook("nitro:init", async (nitro) => {
|
|
293
|
-
let prerenderer;
|
|
294
|
-
nitro.hooks.hook("prerender:init", async (_prerenderer) => {
|
|
295
|
-
prerenderer = _prerenderer;
|
|
296
|
-
});
|
|
297
311
|
nitro.hooks.hook("prerender:generate", async (route) => {
|
|
298
312
|
const html = route.contents;
|
|
299
313
|
if (!route.fileName?.endsWith(".html") || !html || ["/200.html", "/404.html"].includes(route.route))
|
|
@@ -301,6 +315,23 @@ function setupPrerenderHandler(_options, nuxt = useNuxt()) {
|
|
|
301
315
|
if (html.match(NuxtRedirectHtmlRegex)) {
|
|
302
316
|
return;
|
|
303
317
|
}
|
|
318
|
+
const extractedMeta = parseHtmlExtractSitemapMeta(html, {
|
|
319
|
+
images: options.discoverImages,
|
|
320
|
+
videos: options.discoverVideos,
|
|
321
|
+
// TODO configurable?
|
|
322
|
+
lastmod: true,
|
|
323
|
+
alternatives: true,
|
|
324
|
+
resolveUrl(s) {
|
|
325
|
+
return s.startsWith("/") ? withSiteUrl(s) : s;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
if (extractedMeta === null) {
|
|
329
|
+
route._sitemap = {
|
|
330
|
+
loc: route.route,
|
|
331
|
+
_sitemap: false
|
|
332
|
+
};
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
304
335
|
route._sitemap = defu(route._sitemap, {
|
|
305
336
|
loc: route.route
|
|
306
337
|
});
|
|
@@ -313,29 +344,14 @@ function setupPrerenderHandler(_options, nuxt = useNuxt()) {
|
|
|
313
344
|
route._sitemap._sitemap = _sitemap;
|
|
314
345
|
}
|
|
315
346
|
}
|
|
316
|
-
route._sitemap = defu(
|
|
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);
|
|
347
|
+
route._sitemap = defu(extractedMeta, route._sitemap);
|
|
326
348
|
});
|
|
327
349
|
nitro.hooks.hook("prerender:done", async () => {
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
nitroModule = await import(String("nitropack"));
|
|
334
|
-
}
|
|
335
|
-
if (!nitroModule) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
await nitroModule.build(prerenderer);
|
|
350
|
+
const globalSources = await generateGlobalSources();
|
|
351
|
+
const childSources = await generateChildSources();
|
|
352
|
+
await mkdir(runtimeAssetsPath, { recursive: true });
|
|
353
|
+
await writeFile(join(runtimeAssetsPath, "global-sources.json"), JSON.stringify(globalSources));
|
|
354
|
+
await writeFile(join(runtimeAssetsPath, "child-sources.json"), JSON.stringify(childSources));
|
|
339
355
|
await prerenderRoute(nitro, options.isMultiSitemap ? "/sitemap_index.xml" : `/${Object.keys(options.sitemaps)[0]}`);
|
|
340
356
|
});
|
|
341
357
|
});
|
|
@@ -344,8 +360,9 @@ async function prerenderRoute(nitro, route) {
|
|
|
344
360
|
const start = Date.now();
|
|
345
361
|
const _route = { route, fileName: route };
|
|
346
362
|
const encodedRoute = encodeURI(route);
|
|
363
|
+
const fetchUrl = withBase(encodedRoute, nitro.options.baseURL);
|
|
347
364
|
const res = await globalThis.$fetch.raw(
|
|
348
|
-
|
|
365
|
+
fetchUrl,
|
|
349
366
|
{
|
|
350
367
|
headers: { "x-nitro-prerender": encodedRoute },
|
|
351
368
|
retry: nitro.options.prerender.retry,
|
|
@@ -359,6 +376,8 @@ async function prerenderRoute(nitro, route) {
|
|
|
359
376
|
const filePath = join(nitro.options.output.publicDir, _route.fileName);
|
|
360
377
|
await mkdir(dirname(filePath), { recursive: true });
|
|
361
378
|
const data = res._data;
|
|
379
|
+
if (data === void 0)
|
|
380
|
+
throw new Error(`No data returned from '${fetchUrl}'`);
|
|
362
381
|
if (filePath.endsWith("json") || typeof data === "object")
|
|
363
382
|
await writeFile(filePath, JSON.stringify(data), "utf8");
|
|
364
383
|
else
|
|
@@ -1079,127 +1098,161 @@ export {}
|
|
|
1079
1098
|
const pagesPromise = createPagesPromise();
|
|
1080
1099
|
const nitroPromise = createNitroPromise();
|
|
1081
1100
|
let resolvedConfigUrls = false;
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1101
|
+
const isValidPrerenderRoute = (r) => {
|
|
1102
|
+
if (["/200.html", "/404.html", "/index.html"].includes(r.route) || r.error || isPathFile(r.route))
|
|
1103
|
+
return false;
|
|
1104
|
+
return r.contentType?.includes("text/html");
|
|
1105
|
+
};
|
|
1106
|
+
const generateGlobalSources = async () => {
|
|
1107
|
+
const { routeRules: routeRules2 } = generateExtraRoutesFromNuxtConfig();
|
|
1108
|
+
const nitro = await nitroPromise;
|
|
1109
|
+
const prerenderedRoutes2 = nitro._prerenderedRoutes || [];
|
|
1110
|
+
const prerenderUrlsFinal = [
|
|
1111
|
+
...prerenderedRoutes2.filter(isValidPrerenderRoute).map((r) => r._sitemap).filter((entry) => entry && (typeof entry === "string" || entry._sitemap !== false))
|
|
1112
|
+
];
|
|
1113
|
+
if (config.debug) {
|
|
1114
|
+
logger.info("Prerendered routes:", prerenderUrlsFinal);
|
|
1115
|
+
}
|
|
1116
|
+
const pageSource = convertNuxtPagesToSitemapEntries(await pagesPromise, {
|
|
1117
|
+
isI18nMapped,
|
|
1118
|
+
autoLastmod: config.autoLastmod,
|
|
1119
|
+
defaultLocale: nuxtI18nConfig.defaultLocale || "en",
|
|
1120
|
+
strategy: nuxtI18nConfig.strategy || "no_prefix",
|
|
1121
|
+
routesNameSeparator: nuxtI18nConfig.routesNameSeparator,
|
|
1122
|
+
normalisedLocales,
|
|
1123
|
+
filter: {
|
|
1124
|
+
include: normalizeFilters(config.include),
|
|
1125
|
+
exclude: normalizeFilters(config.exclude)
|
|
1126
|
+
},
|
|
1127
|
+
isI18nMicro: i18nModule === "nuxt-i18n-micro"
|
|
1128
|
+
});
|
|
1129
|
+
if (!pageSource.length) {
|
|
1130
|
+
pageSource.push(nuxt.options.app.baseURL || "/");
|
|
1131
|
+
}
|
|
1132
|
+
const allPrerenderedPaths = new Set(
|
|
1133
|
+
prerenderedRoutes2.filter(isValidPrerenderRoute).map((r) => r.route)
|
|
1134
|
+
);
|
|
1135
|
+
const dedupedPageSource = pageSource.filter((p) => {
|
|
1136
|
+
const path = typeof p === "string" ? p : p.loc;
|
|
1137
|
+
return !allPrerenderedPaths.has(path);
|
|
1138
|
+
});
|
|
1139
|
+
if (!resolvedConfigUrls && config.urls) {
|
|
1140
|
+
const urls = await resolveUrls(config.urls, { path: "sitemap:urls", logger });
|
|
1141
|
+
if (urls.length) {
|
|
1142
|
+
userGlobalSources.push({
|
|
1143
|
+
context: {
|
|
1144
|
+
name: "sitemap:urls",
|
|
1145
|
+
description: "Set with the `sitemap.urls` config."
|
|
1146
|
+
},
|
|
1147
|
+
urls
|
|
1148
|
+
});
|
|
1108
1149
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
}
|
|
1150
|
+
resolvedConfigUrls = true;
|
|
1151
|
+
}
|
|
1152
|
+
const globalSources = [
|
|
1153
|
+
...userGlobalSources.map((s) => {
|
|
1154
|
+
if (typeof s === "string" || Array.isArray(s)) {
|
|
1155
|
+
return {
|
|
1156
|
+
sourceType: "user",
|
|
1157
|
+
fetch: s
|
|
1158
|
+
};
|
|
1118
1159
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
}),
|
|
1132
|
-
...(config.excludeAppSources === true ? [] : [
|
|
1133
|
-
...appGlobalSources,
|
|
1134
|
-
{
|
|
1135
|
-
context: {
|
|
1136
|
-
name: "nuxt:pages",
|
|
1137
|
-
description: "Generated from your static page files.",
|
|
1138
|
-
tips: [
|
|
1139
|
-
"Can be disabled with `{ excludeAppSources: ['nuxt:pages'] }`."
|
|
1140
|
-
]
|
|
1141
|
-
},
|
|
1142
|
-
urls: pageSource
|
|
1160
|
+
s.sourceType = "user";
|
|
1161
|
+
return s;
|
|
1162
|
+
}),
|
|
1163
|
+
...(config.excludeAppSources === true ? [] : [
|
|
1164
|
+
...appGlobalSources,
|
|
1165
|
+
{
|
|
1166
|
+
context: {
|
|
1167
|
+
name: "nuxt:pages",
|
|
1168
|
+
description: "Generated from your static page files.",
|
|
1169
|
+
tips: [
|
|
1170
|
+
"Can be disabled with `{ excludeAppSources: ['nuxt:pages'] }`."
|
|
1171
|
+
]
|
|
1143
1172
|
},
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1173
|
+
urls: dedupedPageSource
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
context: {
|
|
1177
|
+
name: "nuxt:route-rules",
|
|
1178
|
+
description: "Generated from your route rules config.",
|
|
1179
|
+
tips: [
|
|
1180
|
+
"Can be disabled with `{ excludeAppSources: ['nuxt:route-rules'] }`."
|
|
1181
|
+
]
|
|
1153
1182
|
},
|
|
1154
|
-
|
|
1183
|
+
urls: routeRules2
|
|
1184
|
+
},
|
|
1185
|
+
{
|
|
1186
|
+
context: {
|
|
1187
|
+
name: "nuxt:prerender",
|
|
1188
|
+
description: "Generated at build time when prerendering.",
|
|
1189
|
+
tips: [
|
|
1190
|
+
"Can be disabled with `{ excludeAppSources: ['nuxt:prerender'] }`."
|
|
1191
|
+
]
|
|
1192
|
+
},
|
|
1193
|
+
urls: prerenderUrlsFinal
|
|
1194
|
+
}
|
|
1195
|
+
]).filter((s) => !config.excludeAppSources.includes(s.context.name) && (!!s.urls?.length || !!s.fetch)).map((s) => {
|
|
1196
|
+
s.sourceType = "app";
|
|
1197
|
+
return s;
|
|
1198
|
+
})
|
|
1199
|
+
];
|
|
1200
|
+
return globalSources;
|
|
1201
|
+
};
|
|
1202
|
+
const extraSitemapModules = typeof config.sitemaps == "object" ? Object.keys(config.sitemaps).filter((n) => n !== "index") : [];
|
|
1203
|
+
const sitemapSources = {};
|
|
1204
|
+
const generateChildSources = async () => {
|
|
1205
|
+
for (const sitemapName of extraSitemapModules) {
|
|
1206
|
+
sitemapSources[sitemapName] = sitemapSources[sitemapName] || [];
|
|
1207
|
+
const definition = config.sitemaps[sitemapName];
|
|
1208
|
+
if (!sitemapSources[sitemapName].length) {
|
|
1209
|
+
if (definition.urls) {
|
|
1210
|
+
sitemapSources[sitemapName].push({
|
|
1155
1211
|
context: {
|
|
1156
|
-
name:
|
|
1157
|
-
description: "
|
|
1158
|
-
tips: [
|
|
1159
|
-
"Can be disabled with `{ excludeAppSources: ['nuxt:prerender'] }`."
|
|
1160
|
-
]
|
|
1212
|
+
name: `sitemaps:${sitemapName}:urls`,
|
|
1213
|
+
description: "Set with the `sitemap.urls` config."
|
|
1161
1214
|
},
|
|
1162
|
-
urls:
|
|
1163
|
-
}
|
|
1164
|
-
]).filter((s) => !config.excludeAppSources.includes(s.context.name) && (!!s.urls?.length || !!s.fetch)).map((s) => {
|
|
1165
|
-
s.sourceType = "app";
|
|
1166
|
-
return s;
|
|
1167
|
-
})
|
|
1168
|
-
];
|
|
1169
|
-
return `export const sources = ${JSON.stringify(globalSources, null, 4)}`;
|
|
1170
|
-
};
|
|
1171
|
-
const extraSitemapModules = typeof config.sitemaps == "object" ? Object.keys(config.sitemaps).filter((n) => n !== "index") : [];
|
|
1172
|
-
const sitemapSources = {};
|
|
1173
|
-
nitroConfig.virtual[`#sitemap-virtual/child-sources.mjs`] = async () => {
|
|
1174
|
-
for (const sitemapName of extraSitemapModules) {
|
|
1175
|
-
sitemapSources[sitemapName] = sitemapSources[sitemapName] || [];
|
|
1176
|
-
const definition = config.sitemaps[sitemapName];
|
|
1177
|
-
if (!sitemapSources[sitemapName].length) {
|
|
1178
|
-
if (definition.urls) {
|
|
1179
|
-
sitemapSources[sitemapName].push({
|
|
1180
|
-
context: {
|
|
1181
|
-
name: `sitemaps:${sitemapName}:urls`,
|
|
1182
|
-
description: "Set with the `sitemap.urls` config."
|
|
1183
|
-
},
|
|
1184
|
-
urls: await resolveUrls(definition.urls, { path: `sitemaps:${sitemapName}:urls`, logger })
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
sitemapSources[sitemapName].push(
|
|
1188
|
-
...(definition.sources || []).map((s) => {
|
|
1189
|
-
if (typeof s === "string" || Array.isArray(s)) {
|
|
1190
|
-
return {
|
|
1191
|
-
sourceType: "user",
|
|
1192
|
-
fetch: s
|
|
1193
|
-
};
|
|
1194
|
-
}
|
|
1195
|
-
s.sourceType = "user";
|
|
1196
|
-
return s;
|
|
1197
|
-
})
|
|
1198
|
-
);
|
|
1215
|
+
urls: await resolveUrls(definition.urls, { path: `sitemaps:${sitemapName}:urls`, logger })
|
|
1216
|
+
});
|
|
1199
1217
|
}
|
|
1218
|
+
sitemapSources[sitemapName].push(
|
|
1219
|
+
...(definition.sources || []).map((s) => {
|
|
1220
|
+
if (typeof s === "string" || Array.isArray(s)) {
|
|
1221
|
+
return {
|
|
1222
|
+
sourceType: "user",
|
|
1223
|
+
fetch: s
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
s.sourceType = "user";
|
|
1227
|
+
return s;
|
|
1228
|
+
})
|
|
1229
|
+
);
|
|
1200
1230
|
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1231
|
+
}
|
|
1232
|
+
return sitemapSources;
|
|
1233
|
+
};
|
|
1234
|
+
nuxt.hooks.hook("nitro:config", (nitroConfig) => {
|
|
1235
|
+
nitroConfig.virtual = nitroConfig.virtual || {};
|
|
1236
|
+
if (!nitroConfig.virtual["#sitemap-virtual/read-sources.mjs"]) {
|
|
1237
|
+
nitroConfig.virtual["#sitemap-virtual/read-sources.mjs"] = `
|
|
1238
|
+
export async function readSourcesFromFilesystem() {
|
|
1239
|
+
return null
|
|
1240
|
+
}
|
|
1241
|
+
`;
|
|
1242
|
+
}
|
|
1243
|
+
if (prerenderSitemap) {
|
|
1244
|
+
nitroConfig.virtual["#sitemap-virtual/global-sources.mjs"] = `export const sources = []`;
|
|
1245
|
+
nitroConfig.virtual[`#sitemap-virtual/child-sources.mjs`] = `export const sources = {}`;
|
|
1246
|
+
} else {
|
|
1247
|
+
nitroConfig.virtual["#sitemap-virtual/global-sources.mjs"] = async () => {
|
|
1248
|
+
const globalSources = await generateGlobalSources();
|
|
1249
|
+
return `export const sources = ${JSON.stringify(globalSources, null, 4)}`;
|
|
1250
|
+
};
|
|
1251
|
+
nitroConfig.virtual[`#sitemap-virtual/child-sources.mjs`] = async () => {
|
|
1252
|
+
const childSources = await generateChildSources();
|
|
1253
|
+
return `export const sources = ${JSON.stringify(childSources, null, 4)}`;
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1203
1256
|
});
|
|
1204
1257
|
if (config.xsl === "/__sitemap__/style.xsl") {
|
|
1205
1258
|
addServerHandler({
|
|
@@ -1214,7 +1267,7 @@ export {}
|
|
|
1214
1267
|
route: `/${config.sitemapName}`,
|
|
1215
1268
|
handler: resolve("./runtime/server/routes/sitemap.xml")
|
|
1216
1269
|
});
|
|
1217
|
-
setupPrerenderHandler({ runtimeConfig, logger });
|
|
1270
|
+
setupPrerenderHandler({ runtimeConfig, logger, generateGlobalSources, generateChildSources });
|
|
1218
1271
|
}
|
|
1219
1272
|
});
|
|
1220
1273
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("nitropack").NitroAppPlugin;
|
|
1
|
+
declare const _default: import("nitropack/types").NitroAppPlugin;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("nitropack").NitroAppPlugin;
|
|
1
|
+
declare const _default: import("nitropack/types").NitroAppPlugin;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("nitropack").NitroAppPlugin;
|
|
1
|
+
declare const _default: import("nitropack/types").NitroAppPlugin;
|
|
2
2
|
export default _default;
|
|
@@ -36,5 +36,10 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
|
|
|
36
36
|
minify: boolean;
|
|
37
37
|
};
|
|
38
38
|
globalSources: import("../../../types.js").SitemapSourceResolved[];
|
|
39
|
+
siteConfig: {
|
|
40
|
+
[x: string]: any;
|
|
41
|
+
[x: number]: any;
|
|
42
|
+
url: string;
|
|
43
|
+
};
|
|
39
44
|
}>>;
|
|
40
45
|
export default _default;
|
|
@@ -5,14 +5,15 @@ import {
|
|
|
5
5
|
globalSitemapSources,
|
|
6
6
|
resolveSitemapSources
|
|
7
7
|
} from "../../sitemap/urlset/sources.js";
|
|
8
|
-
import {
|
|
8
|
+
import { getNitroOrigin, getSiteConfig } from "#site-config/server/composables";
|
|
9
9
|
export default defineEventHandler(async (e) => {
|
|
10
10
|
const _runtimeConfig = useSitemapRuntimeConfig();
|
|
11
|
+
const siteConfig = getSiteConfig(e);
|
|
11
12
|
const { sitemaps: _sitemaps } = _runtimeConfig;
|
|
12
13
|
const runtimeConfig = { ..._runtimeConfig };
|
|
13
14
|
delete runtimeConfig.sitemaps;
|
|
14
15
|
const globalSources = await globalSitemapSources();
|
|
15
|
-
const nitroOrigin =
|
|
16
|
+
const nitroOrigin = getNitroOrigin(e);
|
|
16
17
|
const sitemaps = {};
|
|
17
18
|
for (const s of Object.keys(_sitemaps)) {
|
|
18
19
|
sitemaps[s] = {
|
|
@@ -24,6 +25,7 @@ export default defineEventHandler(async (e) => {
|
|
|
24
25
|
nitroOrigin,
|
|
25
26
|
sitemaps,
|
|
26
27
|
runtimeConfig,
|
|
27
|
-
globalSources: await resolveSitemapSources(globalSources, e)
|
|
28
|
+
globalSources: await resolveSitemapSources(globalSources, e),
|
|
29
|
+
siteConfig: { ...siteConfig }
|
|
28
30
|
};
|
|
29
31
|
});
|
|
@@ -230,8 +230,13 @@ export async function buildSitemapUrls(sitemap, resolvers, runtimeConfig, nitro)
|
|
|
230
230
|
await nitro?.hooks.callHook("sitemap:input", resolvedCtx);
|
|
231
231
|
const enhancedUrls = resolveSitemapEntries(sitemap, resolvedCtx.urls, { autoI18n, isI18nMapped }, resolvers);
|
|
232
232
|
const filteredUrls = enhancedUrls.filter((e) => {
|
|
233
|
-
if (
|
|
233
|
+
if (e._sitemap === false)
|
|
234
|
+
return false;
|
|
235
|
+
if (isMultiSitemap && e._sitemap && sitemap.sitemapName) {
|
|
236
|
+
if (sitemap._isChunking)
|
|
237
|
+
return sitemap.sitemapName.startsWith(e._sitemap + "-");
|
|
234
238
|
return e._sitemap === sitemap.sitemapName;
|
|
239
|
+
}
|
|
235
240
|
return true;
|
|
236
241
|
});
|
|
237
242
|
const sortedUrls = maybeSort(filteredUrls);
|
|
@@ -116,11 +116,27 @@ export async function fetchDataSource(input, event) {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
export function globalSitemapSources() {
|
|
120
|
-
|
|
119
|
+
export async function globalSitemapSources() {
|
|
120
|
+
if (import.meta.prerender) {
|
|
121
|
+
const { readSourcesFromFilesystem } = await import("#sitemap-virtual/read-sources.mjs");
|
|
122
|
+
const sources = await readSourcesFromFilesystem("global-sources.json");
|
|
123
|
+
if (sources)
|
|
124
|
+
return sources;
|
|
125
|
+
}
|
|
126
|
+
const m = await import("#sitemap-virtual/global-sources.mjs");
|
|
127
|
+
return m.sources;
|
|
121
128
|
}
|
|
122
|
-
export function childSitemapSources(definition) {
|
|
123
|
-
|
|
129
|
+
export async function childSitemapSources(definition) {
|
|
130
|
+
if (!definition?._hasSourceChunk)
|
|
131
|
+
return [];
|
|
132
|
+
if (import.meta.prerender) {
|
|
133
|
+
const { readSourcesFromFilesystem } = await import("#sitemap-virtual/read-sources.mjs");
|
|
134
|
+
const allSources = await readSourcesFromFilesystem("child-sources.json");
|
|
135
|
+
if (allSources)
|
|
136
|
+
return allSources[definition.sitemapName] || [];
|
|
137
|
+
}
|
|
138
|
+
const m = await import("#sitemap-virtual/child-sources.mjs");
|
|
139
|
+
return m.sources[definition.sitemapName] || [];
|
|
124
140
|
}
|
|
125
141
|
export async function resolveSitemapSources(sources, event) {
|
|
126
142
|
return (await Promise.all(
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -370,7 +370,7 @@ export interface SitemapUrl {
|
|
|
370
370
|
images?: Array<ImageEntry>;
|
|
371
371
|
videos?: Array<VideoEntry>;
|
|
372
372
|
_i18nTransform?: boolean;
|
|
373
|
-
_sitemap?: string;
|
|
373
|
+
_sitemap?: string | false;
|
|
374
374
|
}
|
|
375
375
|
export type SitemapStrict = Required<SitemapUrl>;
|
|
376
376
|
export interface AlternativeEntry {
|
|
@@ -406,7 +406,7 @@ export interface GoogleNewsEntry {
|
|
|
406
406
|
export interface ImageEntry {
|
|
407
407
|
loc: string | URL;
|
|
408
408
|
caption?: string;
|
|
409
|
-
|
|
409
|
+
geo_location?: string;
|
|
410
410
|
title?: string;
|
|
411
411
|
license?: string | URL;
|
|
412
412
|
}
|
|
@@ -44,6 +44,7 @@ function parseHtmlExtractSitemapMeta(html, options) {
|
|
|
44
44
|
const videoSources = /* @__PURE__ */ new Map();
|
|
45
45
|
let articleModifiedTime;
|
|
46
46
|
const alternatives = [];
|
|
47
|
+
let isBlocked = false;
|
|
47
48
|
walkSync(doc, (node) => {
|
|
48
49
|
if (node.type === ELEMENT_NODE) {
|
|
49
50
|
const element = node;
|
|
@@ -51,6 +52,13 @@ function parseHtmlExtractSitemapMeta(html, options) {
|
|
|
51
52
|
if (element.name === "main" && !mainElement) {
|
|
52
53
|
mainElement = element;
|
|
53
54
|
}
|
|
55
|
+
if (element.name === "meta") {
|
|
56
|
+
const name = sanitizeString(attrs.name).toLowerCase();
|
|
57
|
+
const content = sanitizeString(attrs.content).toLowerCase();
|
|
58
|
+
if (name === "robots" && (content.includes("noindex") || content.includes("none"))) {
|
|
59
|
+
isBlocked = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
54
62
|
if (options?.lastmod && element.name === "meta") {
|
|
55
63
|
const property = sanitizeString(attrs.property);
|
|
56
64
|
const content = sanitizeString(attrs.content);
|
|
@@ -203,9 +211,12 @@ function parseHtmlExtractSitemapMeta(html, options) {
|
|
|
203
211
|
if (options?.lastmod && articleModifiedTime) {
|
|
204
212
|
payload.lastmod = articleModifiedTime;
|
|
205
213
|
}
|
|
206
|
-
if (options?.alternatives && alternatives.length > 0 && (alternatives.length > 1 || alternatives[0]
|
|
214
|
+
if (options?.alternatives && alternatives.length > 0 && (alternatives.length > 1 || alternatives[0]?.hreflang !== "x-default")) {
|
|
207
215
|
payload.alternatives = alternatives;
|
|
208
216
|
}
|
|
217
|
+
if (isBlocked) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
209
220
|
return payload;
|
|
210
221
|
}
|
|
211
222
|
|
package/dist/utils.d.mts
CHANGED
|
@@ -22,7 +22,7 @@ declare function parseHtmlExtractSitemapMeta(html: string, options?: {
|
|
|
22
22
|
lastmod?: boolean;
|
|
23
23
|
alternatives?: boolean;
|
|
24
24
|
resolveUrl?: (s: string) => string;
|
|
25
|
-
}): Partial<SitemapUrl
|
|
25
|
+
}): Partial<SitemapUrl> | null;
|
|
26
26
|
|
|
27
27
|
export { parseHtmlExtractSitemapMeta, parseSitemapXml };
|
|
28
28
|
export type { SitemapParseResult, SitemapWarning };
|
package/dist/utils.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ declare function parseHtmlExtractSitemapMeta(html: string, options?: {
|
|
|
22
22
|
lastmod?: boolean;
|
|
23
23
|
alternatives?: boolean;
|
|
24
24
|
resolveUrl?: (s: string) => string;
|
|
25
|
-
}): Partial<SitemapUrl
|
|
25
|
+
}): Partial<SitemapUrl> | null;
|
|
26
26
|
|
|
27
27
|
export { parseHtmlExtractSitemapMeta, parseSitemapXml };
|
|
28
28
|
export type { SitemapParseResult, SitemapWarning };
|
package/dist/utils.mjs
CHANGED