@nuxtjs/sitemap 7.5.2 → 8.0.0
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 +8 -2
- package/dist/content.d.mts +62 -39
- package/dist/content.d.ts +62 -39
- package/dist/content.mjs +68 -38
- package/dist/devtools/200.html +1 -0
- package/dist/devtools/404.html +1 -0
- package/dist/devtools/_fonts/4ppnHhMi-pBsWSPo7mY0avYxlDoAg1N3PTzCwXLZ5rA-d9oibkGnTd1JL3tc_xnaVgBLYmOB8kjrK2cvZaqwj9s.woff2 +0 -0
- package/dist/devtools/_fonts/4qBuU9MRVUlPZNPSF7Xom_sK8RBEnfYu-9VXFrdq8A8-8TDwLE1HAj1sQn7XxVWtM_7sIaPM-DTdO3Pf8U2DF1U.woff2 +0 -0
- package/dist/devtools/_fonts/6dYsbWUd_BpKJ7mdDihgOcya1gHXLpJBuMYXux3WMjE-q3fYNS8YbW5n7ZeXI2vSNgkRWW5VDPKAl51SNTjG2qk.woff2 +0 -0
- package/dist/devtools/_fonts/Lr-hqqZZsYmCt0ITUlr1CUrWim9fsKvoDFZliMxgNHY-iTa_Yt_PzhOY9TX7ZXdSlEPim6iRt92xhECwaxWxd5w.woff2 +0 -0
- package/dist/devtools/_fonts/OknHvWI6KtYn1JQBzX7eSpNDBQ8520F9TvSUJYkVf6A-xeZn9253svK_8Q2LD0XEruY_MnEsuCRO5LenPoggC0Y.woff2 +0 -0
- package/dist/devtools/_fonts/PV2hrQG6wq5BlIPDjdL1IcOflycaghyt5MHzlBqZtlo-lb_WexLz3VZqfTN0oi554iBH5tT2j2UFEV-XErCAS3E.woff2 +0 -0
- package/dist/devtools/_fonts/UA7OtwYHwGN_HjcVGTdmiQxUit7FlqkCwxVUWSeXVnQ-B4OXCFOL_tWrYODpQTc07aMaj0c2cewTOmBRWR9tD-A.woff2 +0 -0
- package/dist/devtools/_fonts/VE4cDVCv5MxbFM7ZLoLCGbIpNd71zhp7MDI9lmN5Y7I-xZyDYCUVrd6LV8eVGF3Um3UZjBFuUtDGtvdyTBBRYBo.woff2 +0 -0
- package/dist/devtools/_fonts/fVoGbnMbBFd5L9BBp9fUPavUSkZ_EmsQNSyadkT-108-U4T0khaeLQSIhtt9eVvaCEKJjtWJ4ioRJOf8hvqkWY0.woff2 +0 -0
- package/dist/devtools/_fonts/lQAxeCEs1R0Lw-H9XRU1RlOARQN8J6npRsPjyEDMe5s-_DUSLEkO3tKTuun_gSnDLoQPVEnpOnyqZMOw0ByZ6PA.woff2 +0 -0
- package/dist/devtools/_fonts/lntlqNHKLV2n82yTwMde70QqOjcfLE2XJ5oKZ3vRPWc-z6TxpIZQdWXztWLr9_OFWqt_WJJoeGtuK_-XQMZGQwE.woff2 +0 -0
- package/dist/devtools/_fonts/qxAYvKsXWeYv731eb-h5TRurcdIP_W44mpNdX-HABAk-zUDeMEFlNtNbrwvT9JxLEBg0TphGy70O6RfIoIX_ZwU.woff2 +0 -0
- package/dist/devtools/_nuxt/6-8YL5RT.js +1 -0
- package/dist/devtools/_nuxt/B-CoxLn7.js +1 -0
- package/dist/devtools/_nuxt/BBg_LgdD.js +1 -0
- package/dist/devtools/_nuxt/BFP26XjE.js +1 -0
- package/dist/devtools/_nuxt/BFxFqELk.js +1 -0
- package/dist/devtools/_nuxt/BJ46vUgN.js +22 -0
- package/dist/devtools/_nuxt/BK43-3Xm.js +1 -0
- package/dist/devtools/_nuxt/BUgp7PK5.js +1 -0
- package/dist/devtools/_nuxt/BUwCbG2W.js +1 -0
- package/dist/devtools/_nuxt/BgUkVPML.js +1 -0
- package/dist/devtools/_nuxt/Bl-ESRhh.js +1 -0
- package/dist/devtools/_nuxt/BpntLhpu.js +1 -0
- package/dist/devtools/_nuxt/CMkTWvG2.js +1 -0
- package/dist/devtools/_nuxt/CdSSkj0j.js +6 -0
- package/dist/devtools/_nuxt/Cfg7NvvP.js +3 -0
- package/dist/devtools/_nuxt/Cq2IBCZt.js +1 -0
- package/dist/devtools/_nuxt/D56-uEuD.js +1 -0
- package/dist/devtools/_nuxt/D9eL2h5z.js +1 -0
- package/dist/devtools/_nuxt/DC83McAa.js +154 -0
- package/dist/devtools/_nuxt/DLfyhkbV.js +1 -0
- package/dist/devtools/_nuxt/DRdBN13f.js +1 -0
- package/dist/devtools/_nuxt/DevtoolsEmptyState.CPam6VsX.css +1 -0
- package/dist/devtools/_nuxt/DevtoolsSection.BeqVO-za.css +1 -0
- package/dist/devtools/_nuxt/DuYBAn1h.js +1 -0
- package/dist/devtools/_nuxt/Source.ChvNXxeG.css +1 -0
- package/dist/devtools/_nuxt/_hKGTbzI.js +1 -0
- package/dist/devtools/_nuxt/builds/latest.json +1 -0
- package/dist/devtools/_nuxt/builds/meta/8c443858-dba7-4dd0-b65e-6a31b3bbefed.json +1 -0
- package/dist/devtools/_nuxt/entry.DuwzcCXL.css +2 -0
- package/dist/devtools/_nuxt/error-404.CbnweSUu.css +1 -0
- package/dist/devtools/_nuxt/error-500.DrNDBqZi.css +1 -0
- package/dist/devtools/_nuxt/jxhrXVY1.js +1 -0
- package/dist/devtools/_nuxt/pages.CV7xHNff.css +1 -0
- package/dist/devtools/app-sources/index.html +1 -0
- package/dist/devtools/debug/index.html +1 -0
- package/dist/devtools/docs/index.html +1 -0
- package/dist/devtools/index.html +1 -0
- package/dist/devtools/user-sources/index.html +1 -0
- package/dist/module.d.mts +10 -1
- package/dist/module.d.ts +10 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +398 -432
- package/dist/runtime/server/composables/defineSitemapEventHandler.d.ts +1 -1
- package/dist/runtime/server/kit.d.ts +0 -1
- package/dist/runtime/server/kit.js +5 -7
- package/dist/runtime/server/plugins/warm-up.js +1 -1
- package/dist/runtime/server/robots-polyfill/getPathRobotConfig.d.ts +1 -1
- package/dist/runtime/server/robots-polyfill/getPathRobotConfig.js +1 -1
- package/dist/runtime/server/routes/__sitemap__/debug-production.d.ts +17 -0
- package/dist/runtime/server/routes/__sitemap__/debug-production.js +77 -0
- package/dist/runtime/server/routes/__sitemap__/debug.d.ts +2 -2
- package/dist/runtime/server/routes/__sitemap__/debug.js +23 -4
- package/dist/runtime/server/routes/__sitemap__/nuxt-content-urls-v2.js +1 -1
- package/dist/runtime/server/routes/__sitemap__/nuxt-content-urls-v3.d.ts +1 -3
- package/dist/runtime/server/routes/__sitemap__/nuxt-content-urls-v3.js +24 -12
- package/dist/runtime/server/routes/sitemap.xsl.js +349 -153
- package/dist/runtime/server/sitemap/builder/sitemap-index.js +8 -7
- package/dist/runtime/server/sitemap/builder/sitemap.d.ts +1 -1
- package/dist/runtime/server/sitemap/builder/sitemap.js +24 -7
- package/dist/runtime/server/sitemap/builder/xml.js +55 -25
- package/dist/runtime/server/sitemap/event-handlers.js +15 -6
- package/dist/runtime/server/sitemap/nitro.js +17 -8
- package/dist/runtime/server/sitemap/urlset/normalise.d.ts +2 -1
- package/dist/runtime/server/sitemap/urlset/normalise.js +25 -1
- package/dist/runtime/server/sitemap/urlset/sources.js +3 -3
- package/dist/runtime/types.d.ts +14 -8
- package/dist/runtime/utils-pure.d.ts +3 -4
- package/dist/runtime/utils-pure.js +13 -41
- package/dist/shared/{sitemap.Bj0OAEtK.mjs → sitemap.B99ug6A9.mjs} +9 -5
- package/dist/utils.d.mts +21 -10
- package/dist/utils.d.ts +21 -10
- package/dist/utils.mjs +62 -8
- package/package.json +49 -49
- 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/CVDC-Ayb.js +0 -155
- 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/1e2c692d-9f57-4b49-a518-f0dad9ea1e8b.json +0 -1
- package/dist/client/_nuxt/byQmnvHb.js +0 -1
- package/dist/client/_nuxt/cP7UVfHI.js +0 -1
- package/dist/client/_nuxt/entry.Ci1pP-eR.css +0 -1
- package/dist/client/_nuxt/error-404.DHoMe5Vi.css +0 -1
- package/dist/client/_nuxt/error-500.Da7n0rc6.css +0 -1
- package/dist/client/index.html +0 -1
- package/dist/client/sitemap.xml +0 -7
- package/virtual.d.ts +0 -15
package/dist/module.mjs
CHANGED
|
@@ -1,275 +1,43 @@
|
|
|
1
|
-
import { useNuxt,
|
|
2
|
-
import { withHttps, withBase, joinURL, withTrailingSlash, withoutLeadingSlash, withLeadingSlash, withoutTrailingSlash } from 'ufo';
|
|
3
|
-
import { withSiteUrl, installNuxtSiteConfig } from 'nuxt-site-config/kit';
|
|
1
|
+
import { useNuxt, hasNuxtModule, addTypeTemplate, addTemplate, defineNuxtModule, createResolver, useLogger, getNuxtModuleVersion, hasNuxtModuleCompatibility, addServerImports, addPrerenderRoutes, addServerPlugin, resolveModule, addServerHandler } from '@nuxt/kit';
|
|
4
2
|
import { defu } from 'defu';
|
|
3
|
+
import { withSiteUrl, installNuxtSiteConfig } from 'nuxt-site-config/kit';
|
|
4
|
+
import { isPathFile } from 'nuxt-site-config/urls';
|
|
5
|
+
import { dirname, extname } from 'pathe';
|
|
5
6
|
import { readPackageJSON } from 'pkg-types';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { provider, env } from 'std-env';
|
|
7
|
+
import { withBase, withHttps, withTrailingSlash, withoutLeadingSlash, joinURL, withLeadingSlash, withoutTrailingSlash } from 'ufo';
|
|
8
|
+
import { setupDevToolsUI as setupDevToolsUI$1 } from 'nuxtseo-shared/devtools';
|
|
9
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
10
10
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
11
11
|
import { join } from 'node:path';
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
12
|
+
import { colors } from 'consola/utils';
|
|
13
|
+
import { splitForLocales, createPathFilter } from '../dist/runtime/utils-pure.js';
|
|
14
|
+
import { isNuxtGenerate, resolveNitroPreset, getNuxtModuleOptions, resolveNuxtContentVersion, createPagesPromise, createNitroPromise } from 'nuxtseo-shared/kit';
|
|
15
|
+
import { p as parseHtmlExtractSitemapMeta } from './shared/sitemap.B99ug6A9.mjs';
|
|
14
16
|
import { normaliseDate } from '../dist/runtime/server/sitemap/urlset/normalise.js';
|
|
15
|
-
import {
|
|
17
|
+
import { splitPathForI18nLocales as splitPathForI18nLocales$1, normalizeLocales, generatePathForI18nPages } from 'nuxtseo-shared/i18n';
|
|
16
18
|
import 'ultrahtml';
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 && match[1]) {
|
|
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
|
-
}
|
|
20
|
+
function setupDevToolsUI(_options, resolve, nuxt = useNuxt()) {
|
|
21
|
+
setupDevToolsUI$1(
|
|
22
|
+
{ route: "/__nuxt-sitemap", name: "sitemap", title: "Sitemap", icon: "carbon:load-balancer-application" },
|
|
23
|
+
resolve,
|
|
24
|
+
nuxt
|
|
82
25
|
);
|
|
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
|
-
const stats = statSync(p.page.file, { throwIfNoEntry: false });
|
|
103
|
-
if (stats?.mtime)
|
|
104
|
-
p.lastmod = stats.mtime;
|
|
105
|
-
}
|
|
106
|
-
if (p.page?.meta?.sitemap) {
|
|
107
|
-
p = defu(p.page.meta.sitemap, p);
|
|
108
|
-
}
|
|
109
|
-
return p;
|
|
110
|
-
});
|
|
111
|
-
const localeGroups = {};
|
|
112
|
-
pagesWithMeta.reduce((acc, e) => {
|
|
113
|
-
if (e.page.name?.includes(routesNameSeparator)) {
|
|
114
|
-
const [name, locale] = e.page.name.split(routesNameSeparator);
|
|
115
|
-
if (!name)
|
|
116
|
-
return acc;
|
|
117
|
-
if (!acc[name])
|
|
118
|
-
acc[name] = [];
|
|
119
|
-
const { _sitemap } = config.normalisedLocales.find((l) => l.code === locale) || { _sitemap: locale };
|
|
120
|
-
acc[name].push({ ...e, _sitemap: config.isI18nMapped ? _sitemap : void 0, locale });
|
|
121
|
-
} else {
|
|
122
|
-
acc.default = acc.default || [];
|
|
123
|
-
acc.default.push(e);
|
|
124
|
-
}
|
|
125
|
-
return acc;
|
|
126
|
-
}, localeGroups);
|
|
127
|
-
return Object.entries(localeGroups).map(([locale, entries]) => {
|
|
128
|
-
if (locale === "default") {
|
|
129
|
-
return entries.map((e) => {
|
|
130
|
-
const [name] = (e.page?.name || "").split(routesNameSeparator);
|
|
131
|
-
if (!name)
|
|
132
|
-
return false;
|
|
133
|
-
if (localeGroups[name]?.some((a) => a.locale === config.defaultLocale))
|
|
134
|
-
return false;
|
|
135
|
-
const defaultLocale = config.normalisedLocales.find((l) => l.code === config.defaultLocale);
|
|
136
|
-
if (defaultLocale && config.isI18nMapped)
|
|
137
|
-
e._sitemap = defaultLocale._sitemap;
|
|
138
|
-
delete e.page;
|
|
139
|
-
delete e.locale;
|
|
140
|
-
return { ...e };
|
|
141
|
-
}).filter(Boolean);
|
|
142
|
-
}
|
|
143
|
-
return entries.map((entry) => {
|
|
144
|
-
const alternatives = entries.map((entry2) => {
|
|
145
|
-
const locale2 = config.normalisedLocales.find((l) => l.code === entry2.locale);
|
|
146
|
-
if (!pathFilter(entry2.loc))
|
|
147
|
-
return false;
|
|
148
|
-
const href = locale2?.domain ? withHttps(withBase(entry2.loc, locale2?.domain)) : entry2.loc;
|
|
149
|
-
return {
|
|
150
|
-
hreflang: locale2?._hreflang,
|
|
151
|
-
href
|
|
152
|
-
};
|
|
153
|
-
}).filter(Boolean);
|
|
154
|
-
const xDefault = entries.find((a) => a.locale === config.defaultLocale);
|
|
155
|
-
if (xDefault && alternatives.length && pathFilter(xDefault.loc)) {
|
|
156
|
-
const locale2 = config.normalisedLocales.find((l) => l.code === xDefault.locale);
|
|
157
|
-
const href = locale2?.domain ? withHttps(withBase(xDefault.loc, locale2?.domain)) : xDefault.loc;
|
|
158
|
-
alternatives.push({
|
|
159
|
-
hreflang: "x-default",
|
|
160
|
-
href
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
const e = { ...entry };
|
|
164
|
-
if (config.isI18nMapped) {
|
|
165
|
-
const { _sitemap } = config.normalisedLocales.find((l) => l.code === entry.locale) || { _sitemap: locale };
|
|
166
|
-
e._sitemap = _sitemap;
|
|
167
|
-
}
|
|
168
|
-
delete e.page;
|
|
169
|
-
delete e.locale;
|
|
170
|
-
return {
|
|
171
|
-
...e,
|
|
172
|
-
alternatives
|
|
173
|
-
};
|
|
174
|
-
});
|
|
175
|
-
}).filter(Boolean).flat();
|
|
176
|
-
}
|
|
177
|
-
function generateExtraRoutesFromNuxtConfig(nuxt = useNuxt()) {
|
|
178
|
-
const filterForValidPage = (p) => typeof p === "string" && !!p && !extname(p) && !p.startsWith("/api/") && !p.startsWith("/_");
|
|
179
|
-
const routeRules = Object.entries(nuxt.options.routeRules || {}).filter(([k, v]) => {
|
|
180
|
-
if (k.includes("*") || k.includes(".") || k.includes(":"))
|
|
181
|
-
return false;
|
|
182
|
-
if ("robots" in v && typeof v.robots === "boolean" && !v.robots)
|
|
183
|
-
return false;
|
|
184
|
-
return !v.redirect;
|
|
185
|
-
}).map(([k]) => k).filter(filterForValidPage);
|
|
186
|
-
const prerenderUrls = (nuxt.options.nitro.prerender?.routes || []).filter(filterForValidPage);
|
|
187
|
-
return { routeRules, prerenderUrls };
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async function getNuxtModuleOptions(module, nuxt = useNuxt()) {
|
|
191
|
-
const moduleMeta = (typeof module === "string" ? { name: module } : await module.getMeta?.()) || {};
|
|
192
|
-
const { nuxtModule } = await loadNuxtModuleInstance(module, nuxt);
|
|
193
|
-
let moduleEntry;
|
|
194
|
-
for (const m of nuxt.options.modules) {
|
|
195
|
-
if (Array.isArray(m) && m.length >= 2) {
|
|
196
|
-
const _module = m[0];
|
|
197
|
-
const _moduleEntryName = typeof _module === "string" ? _module : (await _module.getMeta?.())?.name || "";
|
|
198
|
-
if (_moduleEntryName === moduleMeta.name)
|
|
199
|
-
moduleEntry = m;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
let inlineOptions = {};
|
|
203
|
-
if (moduleEntry)
|
|
204
|
-
inlineOptions = moduleEntry[1];
|
|
205
|
-
if (nuxtModule.getOptions)
|
|
206
|
-
return nuxtModule.getOptions(inlineOptions, nuxt);
|
|
207
|
-
return inlineOptions;
|
|
208
|
-
}
|
|
209
|
-
function createPagesPromise(nuxt = useNuxt()) {
|
|
210
|
-
return new Promise((resolve) => {
|
|
211
|
-
nuxt.hooks.hook("modules:done", () => {
|
|
212
|
-
if (typeof nuxt.options.pages === "boolean" && nuxt.options.pages === false || typeof nuxt.options.pages === "object" && !nuxt.options.pages.enabled) {
|
|
213
|
-
return resolve([]);
|
|
214
|
-
}
|
|
215
|
-
extendPages(resolve);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
function createNitroPromise(nuxt = useNuxt()) {
|
|
220
|
-
return new Promise((resolve) => {
|
|
221
|
-
nuxt.hooks.hook("nitro:init", (nitro) => {
|
|
222
|
-
resolve(nitro);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
const autodetectableProviders = {
|
|
227
|
-
azure_static: "azure",
|
|
228
|
-
cloudflare_pages: "cloudflare-pages",
|
|
229
|
-
netlify: "netlify",
|
|
230
|
-
stormkit: "stormkit",
|
|
231
|
-
vercel: "vercel",
|
|
232
|
-
cleavr: "cleavr",
|
|
233
|
-
stackblitz: "stackblitz"
|
|
234
|
-
};
|
|
235
|
-
const autodetectableStaticProviders = {
|
|
236
|
-
netlify: "netlify-static",
|
|
237
|
-
vercel: "vercel-static"
|
|
238
|
-
};
|
|
239
|
-
function detectTarget(options = {}) {
|
|
240
|
-
return options?.static ? autodetectableStaticProviders[provider] : autodetectableProviders[provider];
|
|
241
|
-
}
|
|
242
|
-
function resolveNitroPreset(nitroConfig) {
|
|
243
|
-
nitroConfig = nitroConfig || tryUseNuxt()?.options?.nitro;
|
|
244
|
-
if (provider === "stackblitz")
|
|
245
|
-
return "stackblitz";
|
|
246
|
-
let preset;
|
|
247
|
-
if (nitroConfig && nitroConfig?.preset)
|
|
248
|
-
preset = nitroConfig.preset;
|
|
249
|
-
if (!preset)
|
|
250
|
-
preset = env.NITRO_PRESET || env.SERVER_PRESET || detectTarget() || "node-server";
|
|
251
|
-
return preset.replace("_", "-");
|
|
252
26
|
}
|
|
253
27
|
|
|
254
28
|
function formatPrerenderRoute(route) {
|
|
255
29
|
let str = ` \u251C\u2500 ${route.route} (${route.generateTimeMS}ms)`;
|
|
256
30
|
if (route.error) {
|
|
257
|
-
const errorColor =
|
|
31
|
+
const errorColor = colors[route.error.statusCode === 404 ? "yellow" : "red"];
|
|
258
32
|
const errorLead = "\u2514\u2500\u2500";
|
|
259
33
|
str += `
|
|
260
|
-
\u2502 ${errorLead} ${errorColor(route.error)}`;
|
|
34
|
+
\u2502 ${errorLead} ${errorColor(route.error.message)}`;
|
|
261
35
|
}
|
|
262
|
-
return
|
|
36
|
+
return colors.gray(str);
|
|
263
37
|
}
|
|
264
38
|
function includesSitemapRoot(sitemapName, routes) {
|
|
265
39
|
return routes.includes(`/__sitemap__/`) || routes.includes(`/sitemap.xml`) || routes.includes(`/${sitemapName}`) || routes.includes("/sitemap_index.xml");
|
|
266
40
|
}
|
|
267
|
-
function isNuxtGenerate(nuxt = useNuxt()) {
|
|
268
|
-
return nuxt.options.nitro.static || nuxt.options._generate || [
|
|
269
|
-
"static",
|
|
270
|
-
"github-pages"
|
|
271
|
-
].includes(resolveNitroPreset());
|
|
272
|
-
}
|
|
273
41
|
const NuxtRedirectHtmlRegex = /<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=([^"]+)"><\/head><\/html>/;
|
|
274
42
|
function setupPrerenderHandler(_options, nuxt = useNuxt()) {
|
|
275
43
|
const { runtimeConfig: options, logger, generateGlobalSources, generateChildSources } = _options;
|
|
@@ -284,7 +52,7 @@ function setupPrerenderHandler(_options, nuxt = useNuxt()) {
|
|
|
284
52
|
const shouldHookIntoPrerender = prerenderSitemap || nuxt.options.nitro.prerender.routes.length && nuxt.options.nitro.prerender.crawlLinks;
|
|
285
53
|
if (isNuxtGenerate() && options.debug) {
|
|
286
54
|
nuxt.options.nitro.prerender.routes.push("/__sitemap__/debug.json");
|
|
287
|
-
logger.info("Adding debug route for sitemap generation:",
|
|
55
|
+
logger.info("Adding debug route for sitemap generation:", colors.cyan("/__sitemap__/debug.json"));
|
|
288
56
|
}
|
|
289
57
|
if (!shouldHookIntoPrerender) {
|
|
290
58
|
return;
|
|
@@ -312,7 +80,7 @@ export async function readSourcesFromFilesystem(filename) {
|
|
|
312
80
|
const html = route.contents;
|
|
313
81
|
if (!route.fileName?.endsWith(".html") || !html || ["/200.html", "/404.html"].includes(route.route))
|
|
314
82
|
return;
|
|
315
|
-
if (
|
|
83
|
+
if (NuxtRedirectHtmlRegex.test(html)) {
|
|
316
84
|
return;
|
|
317
85
|
}
|
|
318
86
|
const extractedMeta = parseHtmlExtractSitemapMeta(html, {
|
|
@@ -366,7 +134,8 @@ async function prerenderSitemapsFromEntry(nitro, entry) {
|
|
|
366
134
|
const processed = /* @__PURE__ */ new Set();
|
|
367
135
|
while (queue.length) {
|
|
368
136
|
const route = queue.shift();
|
|
369
|
-
if (processed.has(route))
|
|
137
|
+
if (processed.has(route))
|
|
138
|
+
continue;
|
|
370
139
|
processed.add(route);
|
|
371
140
|
const { filePath, prerenderUrls } = await prerenderRoute(nitro, route);
|
|
372
141
|
sitemaps.push({
|
|
@@ -407,97 +176,102 @@ async function prerenderRoute(nitro, route) {
|
|
|
407
176
|
return { filePath, prerenderUrls };
|
|
408
177
|
}
|
|
409
178
|
|
|
410
|
-
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
});
|
|
179
|
+
function registerTypeTemplates() {
|
|
180
|
+
const hasRobotsModule = hasNuxtModule("@nuxtjs/robots") || hasNuxtModule("nuxt-simple-robots");
|
|
181
|
+
addTypeTemplate({
|
|
182
|
+
filename: "types/nuxt-sitemap-augments.d.ts",
|
|
183
|
+
getContents: () => {
|
|
184
|
+
const robotsType = hasRobotsModule ? "" : " robots?: boolean\n";
|
|
185
|
+
return `// Generated by @nuxtjs/sitemap
|
|
186
|
+
/// <reference path="./nuxt-sitemap-virtual.d.ts" />
|
|
187
|
+
import type { SitemapUrl, SitemapItemDefaults, SitemapIndexRenderCtx, SitemapInputCtx, SitemapRenderCtx, SitemapOutputHookCtx, SitemapSourcesHookCtx } from '@nuxtjs/sitemap'
|
|
188
|
+
|
|
189
|
+
declare module 'nitropack' {
|
|
190
|
+
interface PrerenderRoute {
|
|
191
|
+
_sitemap?: SitemapUrl
|
|
192
|
+
}
|
|
193
|
+
interface NitroRouteRules {
|
|
194
|
+
${robotsType} sitemap?: SitemapItemDefaults | false
|
|
195
|
+
}
|
|
196
|
+
interface NitroRouteConfig {
|
|
197
|
+
${robotsType} sitemap?: SitemapItemDefaults | false
|
|
198
|
+
}
|
|
199
|
+
interface NitroRuntimeHooks {
|
|
200
|
+
'sitemap:index-resolved': (ctx: SitemapIndexRenderCtx) => void | Promise<void>
|
|
201
|
+
'sitemap:input': (ctx: SitemapInputCtx) => void | Promise<void>
|
|
202
|
+
'sitemap:resolved': (ctx: SitemapRenderCtx) => void | Promise<void>
|
|
203
|
+
'sitemap:output': (ctx: SitemapOutputHookCtx) => void | Promise<void>
|
|
204
|
+
'sitemap:sources': (ctx: SitemapSourcesHookCtx) => void | Promise<void>
|
|
440
205
|
}
|
|
441
|
-
nuxt.hook("devtools:customTabs", (tabs) => {
|
|
442
|
-
tabs.push({
|
|
443
|
-
// unique identifier
|
|
444
|
-
name: "sitemap",
|
|
445
|
-
// title to display in the tab
|
|
446
|
-
title: "Sitemap",
|
|
447
|
-
// any icon from Iconify, or a URL to an image
|
|
448
|
-
icon: "carbon:load-balancer-application",
|
|
449
|
-
// iframe view
|
|
450
|
-
view: {
|
|
451
|
-
type: "iframe",
|
|
452
|
-
src: DEVTOOLS_UI_ROUTE
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
206
|
}
|
|
457
207
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
208
|
+
declare module 'nitropack/types' {
|
|
209
|
+
interface PrerenderRoute {
|
|
210
|
+
_sitemap?: SitemapUrl
|
|
211
|
+
}
|
|
212
|
+
interface NitroRouteRules {
|
|
213
|
+
${robotsType} sitemap?: SitemapItemDefaults | false
|
|
214
|
+
}
|
|
215
|
+
interface NitroRouteConfig {
|
|
216
|
+
${robotsType} sitemap?: SitemapItemDefaults | false
|
|
217
|
+
}
|
|
218
|
+
interface NitroRuntimeHooks {
|
|
219
|
+
'sitemap:index-resolved': (ctx: SitemapIndexRenderCtx) => void | Promise<void>
|
|
220
|
+
'sitemap:input': (ctx: SitemapInputCtx) => void | Promise<void>
|
|
221
|
+
'sitemap:resolved': (ctx: SitemapRenderCtx) => void | Promise<void>
|
|
222
|
+
'sitemap:output': (ctx: SitemapOutputHookCtx) => void | Promise<void>
|
|
223
|
+
'sitemap:sources': (ctx: SitemapSourcesHookCtx) => void | Promise<void>
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
declare module 'vue-router' {
|
|
228
|
+
interface RouteMeta {
|
|
229
|
+
sitemap?: SitemapItemDefaults | false
|
|
230
|
+
}
|
|
470
231
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
switch (forcedStrategy ?? nuxtI18nConfig.strategy) {
|
|
476
|
-
case "prefix_except_default":
|
|
477
|
-
case "prefix_and_default":
|
|
478
|
-
path = localeCode === nuxtI18nConfig.defaultLocale ? pageLocales : joinURL(localeCode, pageLocales);
|
|
479
|
-
break;
|
|
480
|
-
case "prefix":
|
|
481
|
-
path = joinURL(localeCode, pageLocales);
|
|
482
|
-
break;
|
|
232
|
+
|
|
233
|
+
declare module '#app' {
|
|
234
|
+
interface PageMeta {
|
|
235
|
+
sitemap?: SitemapItemDefaults | false
|
|
483
236
|
}
|
|
484
|
-
return locale?.domain ? withHttps(withBase(path, locale.domain)) : path;
|
|
485
237
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
let locales = mergeOnKey(rawLocales.map((locale) => typeof locale === "string" ? { code: locale } : locale), "code");
|
|
491
|
-
if (onlyLocales.length) {
|
|
492
|
-
locales = locales.filter((locale) => onlyLocales.includes(locale.code));
|
|
238
|
+
|
|
239
|
+
declare module 'nuxt/app' {
|
|
240
|
+
interface PageMeta {
|
|
241
|
+
sitemap?: SitemapItemDefaults | false
|
|
493
242
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export {}
|
|
246
|
+
`;
|
|
497
247
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
248
|
+
});
|
|
249
|
+
addTemplate({
|
|
250
|
+
filename: "types/nuxt-sitemap-virtual.d.ts",
|
|
251
|
+
getContents: () => `declare module '#sitemap-virtual/read-sources.mjs' {
|
|
252
|
+
export function readSourcesFromFilesystem(filename: string): Promise<any | null>
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
declare module '#sitemap-virtual/global-sources.mjs' {
|
|
256
|
+
import type { SitemapSourceBase, SitemapSourceResolved } from '#sitemap/types'
|
|
257
|
+
|
|
258
|
+
export const sources: (SitemapSourceBase | SitemapSourceResolved)[]
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
declare module '#sitemap-virtual/child-sources.mjs' {
|
|
262
|
+
import type { SitemapSourceBase, SitemapSourceResolved } from '#sitemap/types'
|
|
263
|
+
|
|
264
|
+
export const sources: Record<string, (SitemapSourceBase | SitemapSourceResolved)[]>
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
declare module '#sitemap/content-filters' {
|
|
268
|
+
export const filters: Map<string, (entry: any) => boolean>
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
declare module '#sitemap/content-on-url' {
|
|
272
|
+
export const onUrlFns: Map<string, (url: Record<string, unknown>, entry: any, collection: string) => void>
|
|
273
|
+
}
|
|
274
|
+
`
|
|
501
275
|
});
|
|
502
276
|
}
|
|
503
277
|
|
|
@@ -520,6 +294,184 @@ function normalizeFilters(filters) {
|
|
|
520
294
|
}).filter(Boolean);
|
|
521
295
|
}
|
|
522
296
|
|
|
297
|
+
function splitPathForI18nLocales(path, autoI18n) {
|
|
298
|
+
if (typeof path !== "string")
|
|
299
|
+
return path;
|
|
300
|
+
return splitPathForI18nLocales$1(path, autoI18n);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async function resolveUrls(urls, ctx) {
|
|
304
|
+
try {
|
|
305
|
+
if (typeof urls === "function")
|
|
306
|
+
urls = urls();
|
|
307
|
+
urls = await urls;
|
|
308
|
+
} catch (e) {
|
|
309
|
+
ctx.logger.error(`Failed to resolve ${typeof urls} urls.`);
|
|
310
|
+
ctx.logger.error(e);
|
|
311
|
+
return [];
|
|
312
|
+
}
|
|
313
|
+
try {
|
|
314
|
+
urls = JSON.parse(JSON.stringify(urls));
|
|
315
|
+
} catch (e) {
|
|
316
|
+
ctx.logger.error(`Failed to serialize ${typeof urls} \`${ctx.path}\`, please make sure that the urls resolve as a valid array without circular dependencies.`);
|
|
317
|
+
ctx.logger.error(e);
|
|
318
|
+
return [];
|
|
319
|
+
}
|
|
320
|
+
return urls;
|
|
321
|
+
}
|
|
322
|
+
function deepForEachPage(pages, callback, opts, fullpath = null, depth = 0) {
|
|
323
|
+
pages.forEach((page) => {
|
|
324
|
+
let currentPath;
|
|
325
|
+
if (page.path.startsWith("/")) {
|
|
326
|
+
currentPath = page.path;
|
|
327
|
+
} else {
|
|
328
|
+
currentPath = page.path === "" ? fullpath : `${fullpath.replace(/\/$/, "")}/${page.path}`;
|
|
329
|
+
}
|
|
330
|
+
let didCallback = false;
|
|
331
|
+
if (opts.isI18nMicro) {
|
|
332
|
+
const localePattern = /\/:locale\(([^)]+)\)/;
|
|
333
|
+
const match = localePattern.exec(currentPath || "");
|
|
334
|
+
if (match && match[1]) {
|
|
335
|
+
const locales = match[1].split("|");
|
|
336
|
+
locales.forEach((locale) => {
|
|
337
|
+
const subPage = { ...page };
|
|
338
|
+
const localizedPath = (currentPath || "").replace(localePattern, `/${locale}`);
|
|
339
|
+
subPage.name += opts.routesNameSeparator + locale;
|
|
340
|
+
subPage.path = localizedPath;
|
|
341
|
+
callback(subPage, localizedPath || "", depth);
|
|
342
|
+
didCallback = true;
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (!didCallback) {
|
|
347
|
+
callback(page, currentPath || "", depth);
|
|
348
|
+
}
|
|
349
|
+
if (page.children) {
|
|
350
|
+
deepForEachPage(page.children, callback, opts, currentPath, depth + 1);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
function convertNuxtPagesToSitemapEntries(pages, config) {
|
|
355
|
+
const pathFilter = createPathFilter(config.filter);
|
|
356
|
+
const routesNameSeparator = config.routesNameSeparator || "___";
|
|
357
|
+
let flattenedPages = [];
|
|
358
|
+
deepForEachPage(
|
|
359
|
+
pages,
|
|
360
|
+
(page, loc, depth) => {
|
|
361
|
+
flattenedPages.push({ page, loc, depth });
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
...config,
|
|
365
|
+
routesNameSeparator: config.routesNameSeparator || "___"
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
flattenedPages = flattenedPages.filter((page) => !page.loc.includes(":")).filter((page, idx, arr) => {
|
|
369
|
+
return !arr.some((p) => {
|
|
370
|
+
return p.loc === page.loc && p.depth > page.depth;
|
|
371
|
+
});
|
|
372
|
+
}).map((p) => {
|
|
373
|
+
delete p.depth;
|
|
374
|
+
return p;
|
|
375
|
+
});
|
|
376
|
+
if (config.strategy === "prefix_and_default") {
|
|
377
|
+
flattenedPages = flattenedPages.filter((p) => {
|
|
378
|
+
if (p.page?.name) {
|
|
379
|
+
const [, locale] = p.page.name.split(routesNameSeparator);
|
|
380
|
+
return locale !== config.defaultLocale || p.page.name.endsWith("__default");
|
|
381
|
+
}
|
|
382
|
+
return true;
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
const pagesWithMeta = flattenedPages.map((p) => {
|
|
386
|
+
if (config.autoLastmod && p.page.file) {
|
|
387
|
+
const stats = statSync(p.page.file, { throwIfNoEntry: false });
|
|
388
|
+
if (stats?.mtime)
|
|
389
|
+
p.lastmod = stats.mtime;
|
|
390
|
+
}
|
|
391
|
+
if (p.page?.meta?.sitemap) {
|
|
392
|
+
p = defu(p.page.meta.sitemap, p);
|
|
393
|
+
}
|
|
394
|
+
return p;
|
|
395
|
+
});
|
|
396
|
+
const localeGroups = {};
|
|
397
|
+
pagesWithMeta.reduce((acc, e) => {
|
|
398
|
+
if (e.page.name?.includes(routesNameSeparator)) {
|
|
399
|
+
const [name, locale] = e.page.name.split(routesNameSeparator);
|
|
400
|
+
if (!name)
|
|
401
|
+
return acc;
|
|
402
|
+
if (!acc[name])
|
|
403
|
+
acc[name] = [];
|
|
404
|
+
const { _sitemap } = config.normalisedLocales.find((l) => l.code === locale) || { _sitemap: locale };
|
|
405
|
+
acc[name].push({ ...e, _sitemap: config.isI18nMapped ? _sitemap : void 0, locale });
|
|
406
|
+
} else {
|
|
407
|
+
acc.default = acc.default || [];
|
|
408
|
+
acc.default.push(e);
|
|
409
|
+
}
|
|
410
|
+
return acc;
|
|
411
|
+
}, localeGroups);
|
|
412
|
+
return Object.entries(localeGroups).map(([locale, entries]) => {
|
|
413
|
+
if (locale === "default") {
|
|
414
|
+
return entries.map((e) => {
|
|
415
|
+
const [name] = (e.page?.name || "").split(routesNameSeparator);
|
|
416
|
+
if (!name)
|
|
417
|
+
return false;
|
|
418
|
+
if (localeGroups[name]?.some((a) => a.locale === config.defaultLocale))
|
|
419
|
+
return false;
|
|
420
|
+
const defaultLocale = config.normalisedLocales.find((l) => l.code === config.defaultLocale);
|
|
421
|
+
if (defaultLocale && config.isI18nMapped)
|
|
422
|
+
e._sitemap = defaultLocale._sitemap;
|
|
423
|
+
delete e.page;
|
|
424
|
+
delete e.locale;
|
|
425
|
+
return { ...e };
|
|
426
|
+
}).filter(Boolean);
|
|
427
|
+
}
|
|
428
|
+
return entries.map((entry) => {
|
|
429
|
+
const alternatives = entries.map((entry2) => {
|
|
430
|
+
const locale2 = config.normalisedLocales.find((l) => l.code === entry2.locale);
|
|
431
|
+
if (!pathFilter(entry2.loc))
|
|
432
|
+
return false;
|
|
433
|
+
const href = locale2?.domain ? withHttps(withBase(entry2.loc, locale2?.domain)) : entry2.loc;
|
|
434
|
+
return {
|
|
435
|
+
hreflang: locale2?._hreflang,
|
|
436
|
+
href
|
|
437
|
+
};
|
|
438
|
+
}).filter(Boolean);
|
|
439
|
+
const xDefault = entries.find((a) => a.locale === config.defaultLocale);
|
|
440
|
+
if (xDefault && alternatives.length && pathFilter(xDefault.loc)) {
|
|
441
|
+
const locale2 = config.normalisedLocales.find((l) => l.code === xDefault.locale);
|
|
442
|
+
const href = locale2?.domain ? withHttps(withBase(xDefault.loc, locale2?.domain)) : xDefault.loc;
|
|
443
|
+
alternatives.push({
|
|
444
|
+
hreflang: "x-default",
|
|
445
|
+
href
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
const e = { ...entry };
|
|
449
|
+
if (config.isI18nMapped) {
|
|
450
|
+
const { _sitemap } = config.normalisedLocales.find((l) => l.code === entry.locale) || { _sitemap: locale };
|
|
451
|
+
e._sitemap = _sitemap;
|
|
452
|
+
}
|
|
453
|
+
delete e.page;
|
|
454
|
+
delete e.locale;
|
|
455
|
+
return {
|
|
456
|
+
...e,
|
|
457
|
+
alternatives
|
|
458
|
+
};
|
|
459
|
+
});
|
|
460
|
+
}).filter(Boolean).flat();
|
|
461
|
+
}
|
|
462
|
+
function generateExtraRoutesFromNuxtConfig(nuxt = useNuxt()) {
|
|
463
|
+
const filterForValidPage = (p) => typeof p === "string" && !!p && !extname(p) && !p.startsWith("/api/") && !p.startsWith("/_");
|
|
464
|
+
const routeRules = Object.entries(nuxt.options.routeRules || {}).filter(([k, v]) => {
|
|
465
|
+
if (k.includes("*") || k.includes(".") || k.includes(":"))
|
|
466
|
+
return false;
|
|
467
|
+
if ("robots" in v && typeof v.robots === "boolean" && !v.robots)
|
|
468
|
+
return false;
|
|
469
|
+
return !v.redirect;
|
|
470
|
+
}).map(([k]) => k).filter(filterForValidPage);
|
|
471
|
+
const prerenderUrls = (nuxt.options.nitro.prerender?.routes || []).filter(filterForValidPage);
|
|
472
|
+
return { routeRules, prerenderUrls };
|
|
473
|
+
}
|
|
474
|
+
|
|
523
475
|
const module$1 = defineNuxtModule({
|
|
524
476
|
meta: {
|
|
525
477
|
name: "@nuxtjs/sitemap",
|
|
@@ -538,7 +490,7 @@ const module$1 = defineNuxtModule({
|
|
|
538
490
|
optional: true
|
|
539
491
|
},
|
|
540
492
|
"nuxt-site-config": {
|
|
541
|
-
version: ">=3"
|
|
493
|
+
version: ">=3.2"
|
|
542
494
|
},
|
|
543
495
|
"@nuxt/content": {
|
|
544
496
|
version: ">=2",
|
|
@@ -591,6 +543,8 @@ const module$1 = defineNuxtModule({
|
|
|
591
543
|
nuxt.options.alias["#sitemap"] = resolve("./runtime");
|
|
592
544
|
nuxt.options.nitro.alias = nuxt.options.nitro.alias || {};
|
|
593
545
|
nuxt.options.nitro.alias["#sitemap"] = resolve("./runtime");
|
|
546
|
+
nuxt.options.experimental.extraPageMetaExtractionKeys = nuxt.options.experimental.extraPageMetaExtractionKeys || [];
|
|
547
|
+
nuxt.options.experimental.extraPageMetaExtractionKeys.push("sitemap");
|
|
594
548
|
config.xslColumns = config.xslColumns || [
|
|
595
549
|
{ label: "URL", width: "50%" },
|
|
596
550
|
{ label: "Images", width: "25%", select: "count(image:image)" },
|
|
@@ -649,9 +603,6 @@ const module$1 = defineNuxtModule({
|
|
|
649
603
|
if (i18nVersion && i18nModule === "@nuxtjs/i18n" && !await hasNuxtModuleCompatibility(i18nModule, ">=8"))
|
|
650
604
|
logger.warn(`You are using ${i18nModule} v${i18nVersion}. For the best compatibility, please upgrade to ${i18nModule} v8.0.0 or higher.`);
|
|
651
605
|
nuxtI18nConfig = await getNuxtModuleOptions(i18nModule) || {};
|
|
652
|
-
if (typeof nuxtI18nConfig.includeDefaultLocaleRoute !== "undefined") {
|
|
653
|
-
nuxtI18nConfig.strategy = nuxtI18nConfig.includeDefaultLocaleRoute ? "prefix" : "prefix_except_default";
|
|
654
|
-
}
|
|
655
606
|
normalisedLocales = normalizeLocales(nuxtI18nConfig);
|
|
656
607
|
usingI18nPages = !!Object.keys(nuxtI18nConfig.pages || {}).length;
|
|
657
608
|
if (usingI18nPages && !hasDisabledAutoI18n) {
|
|
@@ -710,16 +661,48 @@ const module$1 = defineNuxtModule({
|
|
|
710
661
|
pages: nuxtI18nConfig.pages
|
|
711
662
|
};
|
|
712
663
|
}
|
|
713
|
-
let canI18nMap = config.sitemaps !== false && nuxtI18nConfig.strategy !== "no_prefix";
|
|
664
|
+
let canI18nMap = !hasDisabledAutoI18n && config.sitemaps !== false && nuxtI18nConfig.strategy !== "no_prefix";
|
|
714
665
|
if (typeof config.sitemaps === "object") {
|
|
715
|
-
const
|
|
716
|
-
|
|
666
|
+
const sitemapEntries = Object.entries(config.sitemaps).filter(([k]) => k !== "index");
|
|
667
|
+
const isSitemapIndexOnly = sitemapEntries.length === 0;
|
|
668
|
+
const hasIncludeAppSources = sitemapEntries.some(([_, v]) => v && typeof v === "object" && v.includeAppSources);
|
|
669
|
+
if (!isSitemapIndexOnly && !hasIncludeAppSources)
|
|
717
670
|
canI18nMap = false;
|
|
718
671
|
}
|
|
719
672
|
if (canI18nMap && resolvedAutoI18n) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
673
|
+
const existingSitemaps = typeof config.sitemaps === "object" ? config.sitemaps : {};
|
|
674
|
+
const i18nSitemaps = [];
|
|
675
|
+
const nonI18nSitemaps = {};
|
|
676
|
+
for (const [name2, cfg] of Object.entries(existingSitemaps)) {
|
|
677
|
+
if (name2 === "index")
|
|
678
|
+
continue;
|
|
679
|
+
if (cfg && typeof cfg === "object" && cfg.includeAppSources) {
|
|
680
|
+
i18nSitemaps.push({ name: name2, cfg });
|
|
681
|
+
} else {
|
|
682
|
+
nonI18nSitemaps[name2] = cfg;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const newSitemaps = {
|
|
686
|
+
index: [...existingSitemaps.index || [], ...config.appendSitemaps || []]
|
|
687
|
+
};
|
|
688
|
+
const hasCustomI18nSitemaps = i18nSitemaps.length > 0;
|
|
689
|
+
if (hasCustomI18nSitemaps) {
|
|
690
|
+
for (const { name: name2, cfg } of i18nSitemaps) {
|
|
691
|
+
for (const locale of resolvedAutoI18n.locales) {
|
|
692
|
+
newSitemaps[`${locale._sitemap}-${name2}`] = {
|
|
693
|
+
includeAppSources: true,
|
|
694
|
+
...cfg.exclude?.length && { exclude: cfg.exclude },
|
|
695
|
+
...cfg.include?.length && { include: cfg.include }
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
} else {
|
|
700
|
+
for (const locale of resolvedAutoI18n.locales) {
|
|
701
|
+
newSitemaps[locale._sitemap] = { includeAppSources: true };
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
Object.assign(newSitemaps, nonI18nSitemaps);
|
|
705
|
+
config.sitemaps = newSitemaps;
|
|
723
706
|
isI18nMapped = true;
|
|
724
707
|
usingMultiSitemaps = true;
|
|
725
708
|
}
|
|
@@ -747,56 +730,12 @@ const module$1 = defineNuxtModule({
|
|
|
747
730
|
}]);
|
|
748
731
|
}
|
|
749
732
|
});
|
|
750
|
-
|
|
751
|
-
filename: "module/nuxt-sitemap.d.ts",
|
|
752
|
-
getContents: (data) => {
|
|
753
|
-
const typesPath = relative(resolve(data.nuxt.options.rootDir, data.nuxt.options.buildDir, "module"), resolve("runtime/types"));
|
|
754
|
-
const types = ` interface PrerenderRoute {
|
|
755
|
-
_sitemap?: import('${typesPath}').SitemapUrl
|
|
756
|
-
}
|
|
757
|
-
interface NitroRouteRules {
|
|
758
|
-
index?: boolean
|
|
759
|
-
sitemap?: import('${typesPath}').SitemapItemDefaults
|
|
760
|
-
}
|
|
761
|
-
interface NitroRouteConfig {
|
|
762
|
-
index?: boolean
|
|
763
|
-
sitemap?: import('${typesPath}').SitemapItemDefaults
|
|
764
|
-
}
|
|
765
|
-
interface NitroRuntimeHooks {
|
|
766
|
-
'sitemap:index-resolved': (ctx: import('${typesPath}').SitemapIndexRenderCtx) => void | Promise<void>
|
|
767
|
-
'sitemap:input': (ctx: import('${typesPath}').SitemapInputCtx) => void | Promise<void>
|
|
768
|
-
'sitemap:resolved': (ctx: import('${typesPath}').SitemapRenderCtx) => void | Promise<void>
|
|
769
|
-
'sitemap:output': (ctx: import('${typesPath}').SitemapOutputHookCtx) => void | Promise<void>
|
|
770
|
-
'sitemap:sources': (ctx: import('${typesPath}').SitemapSourcesHookCtx) => void | Promise<void>
|
|
771
|
-
}`;
|
|
772
|
-
return `// Generated by @nuxtjs/sitemap
|
|
773
|
-
declare module 'nitropack' {
|
|
774
|
-
${types}
|
|
775
|
-
}
|
|
776
|
-
declare module 'nitropack/types' {
|
|
777
|
-
${types}
|
|
778
|
-
}
|
|
779
|
-
declare module 'vue-router' {
|
|
780
|
-
interface RouteMeta {
|
|
781
|
-
sitemap?: import('${typesPath}').SitemapItemDefaults
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
export {}
|
|
786
|
-
`;
|
|
787
|
-
}
|
|
788
|
-
}, {
|
|
789
|
-
node: true,
|
|
790
|
-
nitro: true,
|
|
791
|
-
nuxt: true
|
|
792
|
-
});
|
|
733
|
+
registerTypeTemplates();
|
|
793
734
|
const prerenderedRoutes = nuxt.options.nitro.prerender?.routes || [];
|
|
794
735
|
let prerenderSitemap = isNuxtGenerate() || includesSitemapRoot(config.sitemapName, prerenderedRoutes);
|
|
795
736
|
if (config.zeroRuntime && !prerenderSitemap) {
|
|
796
737
|
prerenderSitemap = true;
|
|
797
|
-
|
|
798
|
-
nuxt.options.nitro.prerender.routes = nuxt.options.nitro.prerender.routes || [];
|
|
799
|
-
nuxt.options.nitro.prerender.routes.push("/sitemap.xml");
|
|
738
|
+
addPrerenderRoutes("/sitemap.xml");
|
|
800
739
|
logger.info("`zeroRuntime` enabled - sitemap routes will be prerendered.");
|
|
801
740
|
}
|
|
802
741
|
const routesPath = config.zeroRuntime ? "./runtime/server/routes/__zero-runtime" : "./runtime/server/routes";
|
|
@@ -817,7 +756,7 @@ export {}
|
|
|
817
756
|
};
|
|
818
757
|
}
|
|
819
758
|
if (usingMultiSitemaps) {
|
|
820
|
-
nuxt.options.nitro.routeRules["/sitemap.xml"] = { redirect: "/sitemap_index.xml" };
|
|
759
|
+
nuxt.options.nitro.routeRules["/sitemap.xml"] = { redirect: withBase("/sitemap_index.xml", nuxt.options.app.baseURL) };
|
|
821
760
|
nuxt.options.nitro.routeRules["/sitemap_index.xml"] = routeRules;
|
|
822
761
|
if (typeof config.sitemaps === "object") {
|
|
823
762
|
for (const k in config.sitemaps) {
|
|
@@ -844,10 +783,10 @@ export {}
|
|
|
844
783
|
addServerPlugin(resolve("./runtime/server/plugins/compression"));
|
|
845
784
|
}
|
|
846
785
|
const isNuxtContentDocumentDriven = !!nuxt.options.content?.documentDriven || config.strictNuxtContentPaths;
|
|
847
|
-
const
|
|
848
|
-
const isNuxtContentV3 =
|
|
786
|
+
const contentVersion = await resolveNuxtContentVersion();
|
|
787
|
+
const isNuxtContentV3 = contentVersion && contentVersion.version === 3;
|
|
849
788
|
const nuxtV3Collections = /* @__PURE__ */ new Set();
|
|
850
|
-
const isNuxtContentV2 =
|
|
789
|
+
const isNuxtContentV2 = contentVersion && contentVersion.version === 2;
|
|
851
790
|
if (isNuxtContentV3) {
|
|
852
791
|
if (nuxt.options._installedModules.some((m) => m.meta.name === "Content")) {
|
|
853
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.");
|
|
@@ -859,41 +798,62 @@ export {}
|
|
|
859
798
|
nuxt.options.alias["@nuxt/content/nitro"] = resolve("./runtime/server/content-compat");
|
|
860
799
|
}
|
|
861
800
|
nuxt.hooks.hook("content:file:afterParse", (ctx) => {
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
ctx.content.
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
ctx.
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
801
|
+
try {
|
|
802
|
+
const content = ctx.content;
|
|
803
|
+
nuxtV3Collections.add(ctx.collection.name);
|
|
804
|
+
if (String(ctx.content.path).includes("/.")) {
|
|
805
|
+
ctx.content.sitemap = null;
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if (!ctx.collection.fields || !("sitemap" in ctx.collection.fields)) {
|
|
809
|
+
ctx.content.sitemap = null;
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
if (typeof content.sitemap !== "undefined" && !content.sitemap) {
|
|
813
|
+
ctx.content.sitemap = null;
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
if (ctx.content.robots === false) {
|
|
817
|
+
ctx.content.sitemap = null;
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
const images = [];
|
|
821
|
+
if (config.discoverImages) {
|
|
822
|
+
images.push(
|
|
823
|
+
...content.body?.value?.filter(
|
|
824
|
+
(c) => ["image", "img", "nuxtimg", "nuxt-img"].includes(c[0])
|
|
825
|
+
).filter((c) => c[1]?.src).map((c) => ({ loc: c[1].src })) || []
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
const lastmod = content.seo?.articleModifiedTime || content.updatedAt;
|
|
829
|
+
const defaults = {
|
|
830
|
+
loc: content.path
|
|
831
|
+
};
|
|
832
|
+
if (images.length > 0)
|
|
833
|
+
defaults.images = images;
|
|
834
|
+
if (lastmod)
|
|
835
|
+
defaults.lastmod = lastmod;
|
|
836
|
+
ctx.content.sitemap = defu(typeof content.sitemap === "object" ? content.sitemap : {}, defaults);
|
|
837
|
+
} catch (e) {
|
|
838
|
+
logger.warn(`Failed to process sitemap data for content file (collection: ${ctx.collection?.name}, path: ${ctx.content?.path}), skipping.`, e);
|
|
875
839
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
840
|
+
});
|
|
841
|
+
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
842
|
+
const filterEntries = [];
|
|
843
|
+
if (globalThis.__sitemapCollectionFilters) {
|
|
844
|
+
for (const [name2, filterFn] of globalThis.__sitemapCollectionFilters.entries())
|
|
845
|
+
filterEntries.push(`filters.set(${JSON.stringify(name2)}, ${filterFn.toString()})`);
|
|
879
846
|
}
|
|
880
|
-
const
|
|
881
|
-
if (
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
(c) => ["image", "img", "nuxtimg", "nuxt-img"].includes(c[0])
|
|
885
|
-
).filter((c) => c[1]?.src).map((c) => ({ loc: c[1].src })) || []
|
|
886
|
-
);
|
|
847
|
+
const onUrlEntries = [];
|
|
848
|
+
if (globalThis.__sitemapCollectionOnUrlFns) {
|
|
849
|
+
for (const [name2, fn] of globalThis.__sitemapCollectionOnUrlFns.entries())
|
|
850
|
+
onUrlEntries.push(`onUrlFns.set(${JSON.stringify(name2)}, ${fn.toString()})`);
|
|
887
851
|
}
|
|
888
|
-
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
defaults.images = images;
|
|
894
|
-
if (lastmod)
|
|
895
|
-
defaults.lastmod = lastmod;
|
|
896
|
-
ctx.content.sitemap = defu(typeof content.sitemap === "object" ? content.sitemap : {}, defaults);
|
|
852
|
+
nitroConfig.virtual = nitroConfig.virtual || {};
|
|
853
|
+
nitroConfig.virtual["#sitemap/content-filters"] = `export const filters = new Map()
|
|
854
|
+
${filterEntries.join("\n")}`;
|
|
855
|
+
nitroConfig.virtual["#sitemap/content-on-url"] = `export const onUrlFns = new Map()
|
|
856
|
+
${onUrlEntries.join("\n")}`;
|
|
897
857
|
});
|
|
898
858
|
addServerHandler({
|
|
899
859
|
route: "/__sitemap__/nuxt-content-urls.json",
|
|
@@ -906,7 +866,7 @@ export {}
|
|
|
906
866
|
context: {
|
|
907
867
|
name: "@nuxt/content@v3:urls",
|
|
908
868
|
description: "Generated from your markdown files.",
|
|
909
|
-
tips: [`Parsing the following collections: ${Array.from(nuxtV3Collections).join(", ")}`]
|
|
869
|
+
tips: nuxtV3Collections.size ? [`Parsing the following collections: ${Array.from(nuxtV3Collections).join(", ")}`] : ["No collections found. Make sure your content collections have a `path` field."]
|
|
910
870
|
},
|
|
911
871
|
fetch: "/__sitemap__/nuxt-content-urls.json"
|
|
912
872
|
});
|
|
@@ -1125,6 +1085,12 @@ export {}
|
|
|
1125
1085
|
route: "/__sitemap__/debug.json",
|
|
1126
1086
|
handler: resolve("./runtime/server/routes/__sitemap__/debug")
|
|
1127
1087
|
});
|
|
1088
|
+
if (nuxt.options.dev) {
|
|
1089
|
+
addServerHandler({
|
|
1090
|
+
route: "/__sitemap__/debug-production.json",
|
|
1091
|
+
handler: resolve("./runtime/server/routes/__sitemap__/debug-production")
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1128
1094
|
if (usingMultiSitemaps) {
|
|
1129
1095
|
addServerHandler({
|
|
1130
1096
|
route: "/__sitemap__/**:sitemap",
|
|
@@ -1291,7 +1257,7 @@ export async function readSourcesFromFilesystem() {
|
|
|
1291
1257
|
}
|
|
1292
1258
|
`;
|
|
1293
1259
|
}
|
|
1294
|
-
if (prerenderSitemap) {
|
|
1260
|
+
if (prerenderSitemap && !nuxt.options.dev) {
|
|
1295
1261
|
nitroConfig.virtual["#sitemap-virtual/global-sources.mjs"] = `export const sources = []`;
|
|
1296
1262
|
nitroConfig.virtual[`#sitemap-virtual/child-sources.mjs`] = `export const sources = {}`;
|
|
1297
1263
|
} else {
|