@nuxtjs/sitemap 5.3.5 → 6.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/200.html +5 -6
- package/dist/client/404.html +5 -6
- package/dist/client/_nuxt/CY7GV1Ne.js +31 -0
- package/dist/client/_nuxt/{AGFfX61t.js → D-VsDbcJ.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/8204446e-0708-4f8e-bc4a-e52330d54aba.json +1 -0
- package/dist/client/_nuxt/{DQoqAi02.js → dsisXUEW.js} +1 -1
- package/dist/client/index.html +5 -6
- package/dist/module.json +1 -1
- package/dist/module.mjs +58 -19
- package/dist/runtime/nitro/composables/getPathRobotConfigPolyfill.d.ts +2 -1
- package/dist/runtime/nitro/composables/getPathRobotConfigPolyfill.js +1 -1
- package/dist/runtime/nitro/routes/__sitemap__/debug.d.ts +1 -0
- package/dist/runtime/nitro/{middleware/[sitemap]-sitemap.xml.d.ts → routes/sitemap/[sitemap].xml.d.ts} +1 -1
- package/dist/runtime/nitro/routes/sitemap/[sitemap].xml.js +20 -0
- package/dist/runtime/nitro/routes/sitemap.xsl.js +2 -1
- package/dist/runtime/nitro/routes/sitemap_index.xml.js +19 -16
- package/dist/runtime/nitro/sitemap/builder/sitemap-index.d.ts +3 -2
- package/dist/runtime/nitro/sitemap/builder/sitemap-index.js +13 -27
- package/dist/runtime/nitro/sitemap/builder/sitemap.d.ts +9 -2
- package/dist/runtime/nitro/sitemap/builder/sitemap.js +153 -53
- package/dist/runtime/nitro/sitemap/nitro.d.ts +1 -1
- package/dist/runtime/nitro/sitemap/nitro.js +46 -11
- package/dist/runtime/nitro/sitemap/urlset/normalise.d.ts +3 -2
- package/dist/runtime/nitro/sitemap/urlset/normalise.js +64 -53
- package/dist/runtime/types.d.ts +26 -2
- package/dist/runtime/utils-pure.d.ts +2 -1
- package/dist/runtime/utils-pure.js +6 -0
- package/package.json +4 -6
- package/dist/client/_nuxt/BG-qYwi8.js +0 -6
- package/dist/client/_nuxt/D0mw_hZ2.js +0 -31
- package/dist/client/_nuxt/builds/meta/ab2ad6a2-f67d-4194-8e33-d46fbc5d1290.json +0 -1
- package/dist/runtime/nitro/middleware/[sitemap]-sitemap.xml.js +0 -23
- package/dist/runtime/nitro/sitemap/urlset/filter.d.ts +0 -5
- package/dist/runtime/nitro/sitemap/urlset/filter.js +0 -24
- package/dist/runtime/nitro/sitemap/urlset/i18n.d.ts +0 -6
- package/dist/runtime/nitro/sitemap/urlset/i18n.js +0 -142
|
@@ -1,16 +1,144 @@
|
|
|
1
|
-
import { defu } from "defu";
|
|
2
1
|
import { resolveSitePath } from "site-config-stack/urls";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { joinURL, withHttps } from "ufo";
|
|
3
|
+
import { preNormalizeEntry } from "../urlset/normalise.js";
|
|
5
4
|
import { childSitemapSources, globalSitemapSources, resolveSitemapSources } from "../urlset/sources.js";
|
|
6
|
-
import { filterSitemapUrls } from "../urlset/filter.js";
|
|
7
|
-
import { applyI18nEnhancements, normaliseI18nSources } from "../urlset/i18n.js";
|
|
8
5
|
import { sortSitemapUrls } from "../urlset/sort.js";
|
|
9
|
-
import { splitForLocales } from "
|
|
10
|
-
import { createNitroRouteRuleMatcher } from "../../kit.js";
|
|
6
|
+
import { createPathFilter, logger, splitForLocales } from "../../../utils-pure.js";
|
|
11
7
|
import { handleEntry, wrapSitemapXml } from "./xml.js";
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export function resolveSitemapEntries(sitemap, sources, runtimeConfig) {
|
|
9
|
+
const {
|
|
10
|
+
autoI18n,
|
|
11
|
+
isI18nMapped
|
|
12
|
+
} = runtimeConfig;
|
|
13
|
+
const filterPath = createPathFilter({
|
|
14
|
+
include: sitemap.include,
|
|
15
|
+
exclude: sitemap.exclude
|
|
16
|
+
});
|
|
17
|
+
const _urls = sources.flatMap((e) => e.urls).map((_e) => {
|
|
18
|
+
const e = preNormalizeEntry(_e);
|
|
19
|
+
if (!e.loc || !filterPath(e.loc))
|
|
20
|
+
return false;
|
|
21
|
+
return e;
|
|
22
|
+
}).filter(Boolean);
|
|
23
|
+
let validI18nUrlsForTransform = [];
|
|
24
|
+
let warnIncorrectI18nTransformUsage = false;
|
|
25
|
+
const withoutPrefixPaths = {};
|
|
26
|
+
if (autoI18n && autoI18n.strategy !== "no_prefix") {
|
|
27
|
+
const localeCodes = autoI18n.locales.map((l) => l.code);
|
|
28
|
+
validI18nUrlsForTransform = _urls.map((_e, i) => {
|
|
29
|
+
if (_e._abs)
|
|
30
|
+
return false;
|
|
31
|
+
const split = splitForLocales(_e.loc, localeCodes);
|
|
32
|
+
let localeCode = split[0];
|
|
33
|
+
const pathWithoutPrefix = split[1];
|
|
34
|
+
if (!localeCode)
|
|
35
|
+
localeCode = autoI18n.defaultLocale;
|
|
36
|
+
const e = _e;
|
|
37
|
+
e._pathWithoutPrefix = pathWithoutPrefix;
|
|
38
|
+
const locale = autoI18n.locales.find((l) => l.code === localeCode);
|
|
39
|
+
if (!locale)
|
|
40
|
+
return false;
|
|
41
|
+
e._locale = locale;
|
|
42
|
+
e._index = i;
|
|
43
|
+
withoutPrefixPaths[pathWithoutPrefix] = withoutPrefixPaths[pathWithoutPrefix] || [];
|
|
44
|
+
if (!withoutPrefixPaths[pathWithoutPrefix].some((e2) => e2._locale.code === locale.code))
|
|
45
|
+
withoutPrefixPaths[pathWithoutPrefix].push(e);
|
|
46
|
+
return e;
|
|
47
|
+
}).filter(Boolean);
|
|
48
|
+
for (const e of validI18nUrlsForTransform) {
|
|
49
|
+
if (!e._i18nTransform && !e.alternatives?.length) {
|
|
50
|
+
const alternatives = withoutPrefixPaths[e._pathWithoutPrefix].map((u) => {
|
|
51
|
+
const entries = [];
|
|
52
|
+
if (u._locale.code === autoI18n.defaultLocale) {
|
|
53
|
+
entries.push({
|
|
54
|
+
href: u.loc,
|
|
55
|
+
hreflang: "x-default"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
entries.push({
|
|
59
|
+
href: u.loc,
|
|
60
|
+
hreflang: u._locale.code || autoI18n.defaultLocale
|
|
61
|
+
});
|
|
62
|
+
return entries;
|
|
63
|
+
}).flat().filter(Boolean);
|
|
64
|
+
if (alternatives.length)
|
|
65
|
+
e.alternatives = alternatives;
|
|
66
|
+
} else if (e._i18nTransform) {
|
|
67
|
+
delete e._i18nTransform;
|
|
68
|
+
if (autoI18n.strategy === "no_prefix") {
|
|
69
|
+
warnIncorrectI18nTransformUsage = true;
|
|
70
|
+
}
|
|
71
|
+
if (autoI18n.differentDomains) {
|
|
72
|
+
e.alternatives = [
|
|
73
|
+
{
|
|
74
|
+
// apply default locale domain
|
|
75
|
+
...autoI18n.locales.find((l) => [l.code, l.iso].includes(autoI18n.defaultLocale)),
|
|
76
|
+
code: "x-default"
|
|
77
|
+
},
|
|
78
|
+
...autoI18n.locales.filter((l) => !!l.domain)
|
|
79
|
+
].map((locale) => {
|
|
80
|
+
return {
|
|
81
|
+
hreflang: locale.iso || locale.code,
|
|
82
|
+
href: joinURL(withHttps(locale.domain), e._pathWithoutPrefix)
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
} else {
|
|
86
|
+
for (const l of autoI18n.locales) {
|
|
87
|
+
let loc = joinURL(`/${l.code}`, e._pathWithoutPrefix);
|
|
88
|
+
if (autoI18n.differentDomains || ["prefix_and_default", "prefix_except_default"].includes(autoI18n.strategy) && l.code === autoI18n.defaultLocale)
|
|
89
|
+
loc = e._pathWithoutPrefix;
|
|
90
|
+
const _sitemap = isI18nMapped ? l.iso || l.code : void 0;
|
|
91
|
+
const newEntry = preNormalizeEntry({
|
|
92
|
+
_sitemap,
|
|
93
|
+
...e,
|
|
94
|
+
_index: void 0,
|
|
95
|
+
_key: `${_sitemap || ""}${loc}`,
|
|
96
|
+
_locale: l,
|
|
97
|
+
loc,
|
|
98
|
+
alternatives: [{ code: "x-default" }, ...autoI18n.locales].map((locale) => {
|
|
99
|
+
const code = locale.code === "x-default" ? autoI18n.defaultLocale : locale.code;
|
|
100
|
+
const isDefault = locale.code === "x-default" || locale.code === autoI18n.defaultLocale;
|
|
101
|
+
let href = "";
|
|
102
|
+
if (autoI18n.strategy === "prefix") {
|
|
103
|
+
href = joinURL("/", code, e._pathWithoutPrefix);
|
|
104
|
+
} else if (["prefix_and_default", "prefix_except_default"].includes(autoI18n.strategy)) {
|
|
105
|
+
if (isDefault) {
|
|
106
|
+
href = e._pathWithoutPrefix;
|
|
107
|
+
} else {
|
|
108
|
+
href = joinURL("/", code, e._pathWithoutPrefix);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const hreflang = locale.iso || locale.code;
|
|
112
|
+
if (!filterPath(href))
|
|
113
|
+
return false;
|
|
114
|
+
return {
|
|
115
|
+
hreflang,
|
|
116
|
+
href
|
|
117
|
+
};
|
|
118
|
+
}).filter(Boolean)
|
|
119
|
+
});
|
|
120
|
+
if (e._locale.code === newEntry._locale.code) {
|
|
121
|
+
_urls[e._index] = newEntry;
|
|
122
|
+
e._index = void 0;
|
|
123
|
+
} else {
|
|
124
|
+
_urls.push(newEntry);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (isI18nMapped) {
|
|
130
|
+
e._sitemap = e._sitemap || e._locale.iso || e._locale.code;
|
|
131
|
+
}
|
|
132
|
+
if (e._index)
|
|
133
|
+
_urls[e._index] = e;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (import.meta.dev && warnIncorrectI18nTransformUsage) {
|
|
137
|
+
logger.warn("You're using _i18nTransform with the `no_prefix` strategy. This will cause issues with the sitemap. Please remove the _i18nTransform flag or change i18n strategy.");
|
|
138
|
+
}
|
|
139
|
+
return _urls;
|
|
140
|
+
}
|
|
141
|
+
export async function buildSitemapUrls(sitemap, resolvers, runtimeConfig) {
|
|
14
142
|
const {
|
|
15
143
|
sitemaps,
|
|
16
144
|
// enhancing
|
|
@@ -20,22 +148,18 @@ export async function buildSitemap(sitemap, resolvers, runtimeConfig) {
|
|
|
20
148
|
// sorting
|
|
21
149
|
sortEntries,
|
|
22
150
|
// chunking
|
|
23
|
-
defaultSitemapsChunkSize
|
|
24
|
-
// xls
|
|
25
|
-
version,
|
|
26
|
-
xsl,
|
|
27
|
-
credits
|
|
151
|
+
defaultSitemapsChunkSize
|
|
28
152
|
} = runtimeConfig;
|
|
29
153
|
const isChunking = typeof sitemaps.chunks !== "undefined" && !Number.isNaN(Number(sitemap.sitemapName));
|
|
30
|
-
function maybeSort(
|
|
31
|
-
return sortEntries ? sortSitemapUrls(
|
|
154
|
+
function maybeSort(urls) {
|
|
155
|
+
return sortEntries ? sortSitemapUrls(urls) : urls;
|
|
32
156
|
}
|
|
33
|
-
function maybeSlice(
|
|
157
|
+
function maybeSlice(urls) {
|
|
34
158
|
if (isChunking && defaultSitemapsChunkSize) {
|
|
35
159
|
const chunk = Number(sitemap.sitemapName);
|
|
36
|
-
return
|
|
160
|
+
return urls.slice(chunk * defaultSitemapsChunkSize, (chunk + 1) * defaultSitemapsChunkSize);
|
|
37
161
|
}
|
|
38
|
-
return
|
|
162
|
+
return urls;
|
|
39
163
|
}
|
|
40
164
|
if (autoI18n?.differentDomains) {
|
|
41
165
|
const domain = autoI18n.locales.find((e) => [e.iso, e.code].includes(sitemap.sitemapName))?.domain;
|
|
@@ -52,41 +176,17 @@ export async function buildSitemap(sitemap, resolvers, runtimeConfig) {
|
|
|
52
176
|
}
|
|
53
177
|
const sources = sitemap.includeAppSources ? await globalSitemapSources() : [];
|
|
54
178
|
sources.push(...await childSitemapSources(sitemap));
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
let routeRules = routeRuleMatcher(path);
|
|
63
|
-
if (autoI18n?.locales && autoI18n?.strategy !== "no_prefix") {
|
|
64
|
-
const match = splitForLocales(path, autoI18n.locales.map((l) => l.code));
|
|
65
|
-
const pathWithoutPrefix = match[1];
|
|
66
|
-
if (pathWithoutPrefix && pathWithoutPrefix !== path)
|
|
67
|
-
routeRules = defu(routeRules, routeRuleMatcher(pathWithoutPrefix));
|
|
68
|
-
}
|
|
69
|
-
if (routeRules.sitemap === false)
|
|
70
|
-
return false;
|
|
71
|
-
if (typeof routeRules.index !== "undefined" && !routeRules.index)
|
|
72
|
-
return false;
|
|
73
|
-
const hasRobotsDisabled = Object.entries(routeRules.headers || {}).some(([name, value]) => name.toLowerCase() === "x-robots-tag" && value.toLowerCase() === "noindex");
|
|
74
|
-
if (routeRules.redirect || hasRobotsDisabled)
|
|
75
|
-
return false;
|
|
76
|
-
return routeRules.sitemap ? defu(e, routeRules.sitemap) : e;
|
|
77
|
-
}).filter(Boolean);
|
|
78
|
-
if (autoI18n?.locales)
|
|
79
|
-
enhancedUrls = applyI18nEnhancements(enhancedUrls, { isI18nMapped, autoI18n, ...sitemap });
|
|
80
|
-
const filteredUrls = filterSitemapUrls(enhancedUrls, { event: resolvers.event, isMultiSitemap, autoI18n, ...sitemap });
|
|
179
|
+
const resolvedSources = await resolveSitemapSources(sources, resolvers.event);
|
|
180
|
+
const enhancedUrls = resolveSitemapEntries(sitemap, resolvedSources, { autoI18n, isI18nMapped });
|
|
181
|
+
const filteredUrls = enhancedUrls.filter((e) => {
|
|
182
|
+
if (isMultiSitemap && e._sitemap && sitemap.sitemapName)
|
|
183
|
+
return e._sitemap === sitemap.sitemapName;
|
|
184
|
+
return true;
|
|
185
|
+
});
|
|
81
186
|
const sortedUrls = maybeSort(filteredUrls);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
urls: slicedUrls,
|
|
86
|
-
sitemapName: sitemap.sitemapName
|
|
87
|
-
};
|
|
88
|
-
await nitro.hooks.callHook("sitemap:resolved", ctx);
|
|
89
|
-
const urls = maybeSort(normaliseSitemapUrls(ctx.urls, resolvers));
|
|
187
|
+
return maybeSlice(sortedUrls);
|
|
188
|
+
}
|
|
189
|
+
export function urlsToXml(urls, resolvers, { version, xsl, credits }) {
|
|
90
190
|
const urlset = urls.map((e) => {
|
|
91
191
|
const keys = Object.keys(e).filter((k) => !k.startsWith("_"));
|
|
92
192
|
return [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { H3Event } from 'h3';
|
|
2
2
|
import type { ModuleRuntimeConfig, NitroUrlResolvers, SitemapDefinition } from '../../types.js';
|
|
3
3
|
export declare function useNitroUrlResolvers(e: H3Event): NitroUrlResolvers;
|
|
4
|
-
export declare function createSitemap(
|
|
4
|
+
export declare function createSitemap(event: H3Event, definition: SitemapDefinition, runtimeConfig: ModuleRuntimeConfig): Promise<string>;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { getQuery, setHeader } from "h3";
|
|
2
2
|
import { fixSlashes } from "site-config-stack/urls";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { defu } from "defu";
|
|
4
|
+
import { mergeOnKey, splitForLocales } from "../../utils-pure.js";
|
|
5
|
+
import { createNitroRouteRuleMatcher } from "../kit.js";
|
|
6
|
+
import { buildSitemapUrls, urlsToXml } from "./builder/sitemap.js";
|
|
7
|
+
import { normaliseEntry } from "./urlset/normalise.js";
|
|
8
|
+
import { sortSitemapUrls } from "./urlset/sort.js";
|
|
9
|
+
import { createSitePathResolver, getPathRobotConfig, useNitroApp, useSiteConfig } from "#imports";
|
|
6
10
|
export function useNitroUrlResolvers(e) {
|
|
7
11
|
const canonicalQuery = getQuery(e).canonical;
|
|
8
12
|
const isShowingCanonical = typeof canonicalQuery !== "undefined" && canonicalQuery !== "false";
|
|
@@ -19,18 +23,49 @@ export function useNitroUrlResolvers(e) {
|
|
|
19
23
|
relativeBaseUrlResolver: createSitePathResolver(e, { absolute: false, withBase: true })
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
|
-
export async function createSitemap(
|
|
26
|
+
export async function createSitemap(event, definition, runtimeConfig) {
|
|
23
27
|
const { sitemapName } = definition;
|
|
24
28
|
const nitro = useNitroApp();
|
|
25
|
-
|
|
29
|
+
const resolvers = useNitroUrlResolvers(event);
|
|
30
|
+
let sitemapUrls = await buildSitemapUrls(definition, resolvers, runtimeConfig);
|
|
31
|
+
const routeRuleMatcher = createNitroRouteRuleMatcher();
|
|
32
|
+
const { autoI18n } = runtimeConfig;
|
|
33
|
+
sitemapUrls = sitemapUrls.map((u) => {
|
|
34
|
+
const path = u._path?.pathname || u.loc;
|
|
35
|
+
if (!getPathRobotConfig(event, { path, skipSiteIndexable: true }).indexable)
|
|
36
|
+
return false;
|
|
37
|
+
let routeRules = routeRuleMatcher(path);
|
|
38
|
+
if (autoI18n?.locales && autoI18n?.strategy !== "no_prefix") {
|
|
39
|
+
const match = splitForLocales(path, autoI18n.locales.map((l) => l.code));
|
|
40
|
+
const pathWithoutPrefix = match[1];
|
|
41
|
+
if (pathWithoutPrefix && pathWithoutPrefix !== path)
|
|
42
|
+
routeRules = defu(routeRules, routeRuleMatcher(pathWithoutPrefix));
|
|
43
|
+
}
|
|
44
|
+
if (routeRules.sitemap === false)
|
|
45
|
+
return false;
|
|
46
|
+
if (typeof routeRules.index !== "undefined" && !routeRules.index || typeof routeRules.robots !== "undefined" && !routeRules.robots) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const hasRobotsDisabled = Object.entries(routeRules.headers || {}).some(([name, value]) => name.toLowerCase() === "x-robots-tag" && value.toLowerCase().includes("noindex"));
|
|
50
|
+
if (routeRules.redirect || hasRobotsDisabled)
|
|
51
|
+
return false;
|
|
52
|
+
return routeRules.sitemap ? defu(u, routeRules.sitemap) : u;
|
|
53
|
+
}).filter(Boolean);
|
|
54
|
+
const resolvedCtx = {
|
|
55
|
+
urls: sitemapUrls,
|
|
56
|
+
sitemapName
|
|
57
|
+
};
|
|
58
|
+
await nitro.hooks.callHook("sitemap:resolved", resolvedCtx);
|
|
59
|
+
const maybeSort = (urls2) => runtimeConfig.sortEntries ? sortSitemapUrls(urls2) : urls2;
|
|
60
|
+
const urls = maybeSort(mergeOnKey(resolvedCtx.urls.map((e) => normaliseEntry(e, definition.defaults, resolvers)), "_key"));
|
|
61
|
+
const sitemap = urlsToXml(urls, resolvers, runtimeConfig);
|
|
26
62
|
const ctx = { sitemap, sitemapName };
|
|
27
63
|
await nitro.hooks.callHook("sitemap:output", ctx);
|
|
28
|
-
|
|
29
|
-
setHeader(e, "Content-Type", "text/xml; charset=UTF-8");
|
|
64
|
+
setHeader(event, "Content-Type", "text/xml; charset=UTF-8");
|
|
30
65
|
if (runtimeConfig.cacheMaxAgeSeconds)
|
|
31
|
-
setHeader(
|
|
66
|
+
setHeader(event, "Cache-Control", `public, max-age=${runtimeConfig.cacheMaxAgeSeconds}, must-revalidate`);
|
|
32
67
|
else
|
|
33
|
-
setHeader(
|
|
34
|
-
|
|
35
|
-
return sitemap;
|
|
68
|
+
setHeader(event, "Cache-Control", `no-cache, no-store`);
|
|
69
|
+
event.context._isSitemap = true;
|
|
70
|
+
return ctx.sitemap;
|
|
36
71
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { NitroUrlResolvers, ResolvedSitemapUrl,
|
|
2
|
-
export declare function
|
|
1
|
+
import type { NitroUrlResolvers, ResolvedSitemapUrl, SitemapUrl } from '../../../types.js';
|
|
2
|
+
export declare function preNormalizeEntry(_e: SitemapUrl | string): ResolvedSitemapUrl;
|
|
3
|
+
export declare function normaliseEntry(_e: ResolvedSitemapUrl, defaults: Omit<SitemapUrl, 'loc'>, resolvers?: NitroUrlResolvers): ResolvedSitemapUrl;
|
|
3
4
|
export declare function isValidW3CDate(d: string): boolean;
|
|
4
5
|
export declare function normaliseDate(date: string | Date): string;
|
|
@@ -1,66 +1,77 @@
|
|
|
1
|
-
import { hasProtocol } from "ufo";
|
|
2
|
-
import {
|
|
1
|
+
import { hasProtocol, parsePath, parseURL } from "ufo";
|
|
2
|
+
import { defu } from "defu";
|
|
3
3
|
import { mergeOnKey } from "../../../utils-pure.js";
|
|
4
4
|
function resolve(s, resolvers) {
|
|
5
|
-
if (typeof s === "undefined")
|
|
5
|
+
if (typeof s === "undefined" || !resolvers)
|
|
6
6
|
return s;
|
|
7
7
|
s = typeof s === "string" ? s : s.toString();
|
|
8
8
|
if (hasProtocol(s, { acceptRelative: true, strict: false }))
|
|
9
9
|
return resolvers.fixSlashes(s);
|
|
10
10
|
return resolvers.canonicalUrlResolver(s);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
12
|
+
function removeTrailingSlash(s) {
|
|
13
|
+
return s.replace(/\/(\?|#|$)/, "$1");
|
|
14
|
+
}
|
|
15
|
+
export function preNormalizeEntry(_e) {
|
|
16
|
+
const e = typeof _e === "string" ? { loc: _e } : { ..._e };
|
|
17
|
+
if (e.url && !e.loc) {
|
|
18
|
+
e.loc = e.url;
|
|
19
|
+
delete e.url;
|
|
20
|
+
}
|
|
21
|
+
e.loc = removeTrailingSlash(e.loc || "");
|
|
22
|
+
e._abs = hasProtocol(e.loc, { acceptRelative: false, strict: false });
|
|
23
|
+
try {
|
|
24
|
+
e._path = e._abs ? parseURL(e.loc) : parsePath(e.loc);
|
|
25
|
+
} catch (e2) {
|
|
26
|
+
e2._path = null;
|
|
27
|
+
}
|
|
28
|
+
if (e._path?.pathname === "")
|
|
29
|
+
e.loc = `${e.loc}/`;
|
|
30
|
+
if (e._path) {
|
|
31
|
+
e._key = `${e._sitemap || ""}${e._path?.pathname || "/"}${e._path.search}`;
|
|
32
|
+
} else {
|
|
33
|
+
e._key = e.loc;
|
|
34
|
+
}
|
|
35
|
+
return e;
|
|
36
|
+
}
|
|
37
|
+
export function normaliseEntry(_e, defaults, resolvers) {
|
|
38
|
+
const e = defu(_e, defaults);
|
|
39
|
+
if (e.lastmod) {
|
|
40
|
+
const date = normaliseDate(e.lastmod);
|
|
41
|
+
if (date)
|
|
42
|
+
e.lastmod = date;
|
|
43
|
+
else
|
|
31
44
|
delete e.lastmod;
|
|
32
|
-
e.loc = resolve(e.loc, resolvers);
|
|
33
|
-
if (e.alternatives) {
|
|
34
|
-
e.alternatives = mergeOnKey(e.alternatives.map((e2) => {
|
|
35
|
-
const a = { ...e2 };
|
|
36
|
-
if (typeof a.href === "string")
|
|
37
|
-
a.href = resolve(a.href, resolvers);
|
|
38
|
-
else if (typeof a.href === "object" && a.href)
|
|
39
|
-
a.href = resolve(a.href.href, resolvers);
|
|
40
|
-
return a;
|
|
41
|
-
}), "hreflang");
|
|
42
|
-
}
|
|
43
|
-
if (e.images) {
|
|
44
|
-
e.images = mergeOnKey(e.images.map((i) => {
|
|
45
|
-
i = { ...i };
|
|
46
|
-
i.loc = resolve(i.loc, resolvers);
|
|
47
|
-
return i;
|
|
48
|
-
}), "loc");
|
|
49
|
-
}
|
|
50
|
-
if (e.videos) {
|
|
51
|
-
e.videos = e.videos.map((v) => {
|
|
52
|
-
v = { ...v };
|
|
53
|
-
if (v.content_loc)
|
|
54
|
-
v.content_loc = resolve(v.content_loc, resolvers);
|
|
55
|
-
return v;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
return e;
|
|
59
45
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
)
|
|
46
|
+
if (!e.lastmod)
|
|
47
|
+
delete e.lastmod;
|
|
48
|
+
e.loc = resolve(e.loc, resolvers);
|
|
49
|
+
if (e.alternatives) {
|
|
50
|
+
e.alternatives = mergeOnKey(e.alternatives.map((e2) => {
|
|
51
|
+
const a = { ...e2 };
|
|
52
|
+
if (typeof a.href === "string")
|
|
53
|
+
a.href = resolve(a.href, resolvers);
|
|
54
|
+
else if (typeof a.href === "object" && a.href)
|
|
55
|
+
a.href = resolve(a.href.href, resolvers);
|
|
56
|
+
return a;
|
|
57
|
+
}), "hreflang");
|
|
58
|
+
}
|
|
59
|
+
if (e.images) {
|
|
60
|
+
e.images = mergeOnKey(e.images.map((i) => {
|
|
61
|
+
i = { ...i };
|
|
62
|
+
i.loc = resolve(i.loc, resolvers);
|
|
63
|
+
return i;
|
|
64
|
+
}), "loc");
|
|
65
|
+
}
|
|
66
|
+
if (e.videos) {
|
|
67
|
+
e.videos = e.videos.map((v) => {
|
|
68
|
+
v = { ...v };
|
|
69
|
+
if (v.content_loc)
|
|
70
|
+
v.content_loc = resolve(v.content_loc, resolvers);
|
|
71
|
+
return v;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return e;
|
|
64
75
|
}
|
|
65
76
|
const IS_VALID_W3C_DATE = [
|
|
66
77
|
/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FetchOptions } from 'ofetch';
|
|
2
2
|
import type { H3Event } from 'h3';
|
|
3
|
+
import type { ParsedURL } from 'ufo';
|
|
3
4
|
export interface ModuleOptions extends SitemapDefinition {
|
|
4
5
|
/**
|
|
5
6
|
* Whether the sitemap.xml should be generated.
|
|
@@ -39,6 +40,12 @@ export interface ModuleOptions extends SitemapDefinition {
|
|
|
39
40
|
* @default false
|
|
40
41
|
*/
|
|
41
42
|
sitemaps?: boolean | MultiSitemapsInput;
|
|
43
|
+
/**
|
|
44
|
+
* The path prefix for the sitemaps.
|
|
45
|
+
*
|
|
46
|
+
* @default /__sitemap__/
|
|
47
|
+
*/
|
|
48
|
+
sitemapsPathPrefix: string;
|
|
42
49
|
/**
|
|
43
50
|
* Sitemaps to append to the sitemap index.
|
|
44
51
|
*
|
|
@@ -193,7 +200,7 @@ export interface AutoI18nConfig {
|
|
|
193
200
|
defaultLocale: string;
|
|
194
201
|
strategy: 'prefix' | 'prefix_except_default' | 'prefix_and_default' | 'no_prefix';
|
|
195
202
|
}
|
|
196
|
-
export interface ModuleRuntimeConfig extends Pick<ModuleOptions, 'cacheMaxAgeSeconds' | 'sitemapName' | 'excludeAppSources' | 'sortEntries' | 'defaultSitemapsChunkSize' | 'xslColumns' | 'xslTips' | 'debug' | 'discoverImages' | 'discoverVideos' | 'autoLastmod' | 'xsl' | 'credits'> {
|
|
203
|
+
export interface ModuleRuntimeConfig extends Pick<ModuleOptions, 'sitemapsPathPrefix' | 'cacheMaxAgeSeconds' | 'sitemapName' | 'excludeAppSources' | 'sortEntries' | 'defaultSitemapsChunkSize' | 'xslColumns' | 'xslTips' | 'debug' | 'discoverImages' | 'discoverVideos' | 'autoLastmod' | 'xsl' | 'credits'> {
|
|
197
204
|
version: string;
|
|
198
205
|
isNuxtContentDocumentDriven: boolean;
|
|
199
206
|
sitemaps: {
|
|
@@ -210,11 +217,28 @@ export interface ModuleRuntimeConfig extends Pick<ModuleOptions, 'cacheMaxAgeSec
|
|
|
210
217
|
export interface SitemapIndexEntry {
|
|
211
218
|
sitemap: string;
|
|
212
219
|
lastmod?: string;
|
|
220
|
+
/**
|
|
221
|
+
* @internal
|
|
222
|
+
*/
|
|
223
|
+
_sitemapName?: string;
|
|
213
224
|
}
|
|
214
225
|
export type FilterInput = (string | RegExp | {
|
|
215
226
|
regex: string;
|
|
216
227
|
});
|
|
217
|
-
export type ResolvedSitemapUrl = Omit<SitemapUrl, 'url'> & Required<Pick<SitemapUrl, 'loc'
|
|
228
|
+
export type ResolvedSitemapUrl = Omit<SitemapUrl, 'url'> & Required<Pick<SitemapUrl, 'loc'>> & {
|
|
229
|
+
/**
|
|
230
|
+
* @internal
|
|
231
|
+
*/
|
|
232
|
+
_key: string;
|
|
233
|
+
/**
|
|
234
|
+
* @internal
|
|
235
|
+
*/
|
|
236
|
+
_path: ParsedURL;
|
|
237
|
+
/**
|
|
238
|
+
* @internal
|
|
239
|
+
*/
|
|
240
|
+
_abs: boolean;
|
|
241
|
+
};
|
|
218
242
|
export interface SitemapDefinition {
|
|
219
243
|
/**
|
|
220
244
|
* A collection include patterns for filtering which URLs end up in the sitemap.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { FilterInput } from './types.js';
|
|
2
|
+
export declare const logger: import("consola").ConsolaInstance;
|
|
2
3
|
export declare function mergeOnKey<T, K extends keyof T>(arr: T[], key: K): T[];
|
|
3
|
-
export declare function splitForLocales(path: string, locales: string[]):
|
|
4
|
+
export declare function splitForLocales(path: string, locales: string[]): [string | null, string];
|
|
4
5
|
/**
|
|
5
6
|
* Transform a literal notation string regex to RegExp
|
|
6
7
|
*/
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { createDefu } from "defu";
|
|
2
2
|
import { parseURL, withLeadingSlash } from "ufo";
|
|
3
3
|
import { createRouter, toRouteMatcher } from "radix3";
|
|
4
|
+
import { createConsola } from "consola";
|
|
5
|
+
export const logger = createConsola({
|
|
6
|
+
defaults: {
|
|
7
|
+
tag: "@nuxt/sitemap"
|
|
8
|
+
}
|
|
9
|
+
});
|
|
4
10
|
const merger = createDefu((obj, key, value) => {
|
|
5
11
|
if (Array.isArray(obj[key]) && Array.isArray(value))
|
|
6
12
|
obj[key] = Array.from(/* @__PURE__ */ new Set([...obj[key], ...value]));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/sitemap",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.0.0-beta.1",
|
|
5
5
|
"description": "Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -64,7 +64,6 @@
|
|
|
64
64
|
"eslint-plugin-n": "^17.9.0",
|
|
65
65
|
"execa": "^9.3.0",
|
|
66
66
|
"nuxt": "^3.12.3",
|
|
67
|
-
"nuxt-icon": "1.0.0-beta.7",
|
|
68
67
|
"typescript": "5.4.5",
|
|
69
68
|
"vitest": "^2.0.3"
|
|
70
69
|
},
|
|
@@ -82,10 +81,9 @@
|
|
|
82
81
|
"client:build": "nuxi generate client",
|
|
83
82
|
"client:dev": "nuxi dev client --port 3300",
|
|
84
83
|
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build && npm run client:build",
|
|
85
|
-
"dev": "nuxi dev
|
|
86
|
-
"dev:
|
|
87
|
-
"dev:
|
|
88
|
-
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare .playground",
|
|
84
|
+
"dev": "nuxi dev playground",
|
|
85
|
+
"dev:build": "nuxi build playground",
|
|
86
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
89
87
|
"release": "pnpm build && bumpp && pnpm -r publish",
|
|
90
88
|
"test": "vitest"
|
|
91
89
|
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{g as m,h as d,l as b,i as k,j as h,k as p,m as x,n as S,q as v,I as N}from"./D0mw_hZ2.js";const C=Object.freeze({left:0,top:0,width:16,height:16}),I=Object.freeze({rotate:0,vFlip:!1,hFlip:!1}),y=Object.freeze({...C,...I});Object.freeze({...y,body:"",hidden:!1});function $(e,t){let s=e.indexOf("xlink:")===-1?"":' xmlns:xlink="http://www.w3.org/1999/xlink"';for(const n in t)s+=" "+n+'="'+t[n]+'"';return'<svg xmlns="http://www.w3.org/2000/svg"'+s+">"+e+"</svg>"}const z=/(-?[0-9.]*[0-9]+[0-9.]*)/g,R=/^-?[0-9.]*[0-9]+[0-9.]*$/g;function j(e,t,s){if(t===1)return e;s=s||100;const n=e.split(z);if(n===null||!n.length)return e;const a=[];let r=n.shift(),o=R.test(r);for(;;){if(o){const c=parseFloat(r);isNaN(c)?a.push(r):a.push(Math.ceil(c*t*s)/s)}else a.push(r);if(r=n.shift(),r===void 0)return a.join("");o=!o}}function q(e){return e.replace(/"/g,"'").replace(/%/g,"%25").replace(/#/g,"%23").replace(/</g,"%3C").replace(/>/g,"%3E").replace(/\s+/g," ")}function P(e){return"data:image/svg+xml,"+q(e)}function T(e){return'url("'+P(e)+'")'}function A(e){if(e.width!==e.height){const t=Math.max(e.width,e.height);return{...e,width:t,height:t,left:e.left-(t-e.width)/2,top:e.top-(t-e.height)/2}}return e}function L(e){const t={display:"inline-block",width:"1em",height:"1em"},s=e.varName;switch(e.pseudoSelector&&(t.content="''"),e.mode){case"background":s&&(t["background-image"]="var(--"+s+")"),t["background-repeat"]="no-repeat",t["background-size"]="100% 100%";break;case"mask":t["background-color"]="currentColor",s&&(t["mask-image"]=t["-webkit-mask-image"]="var(--"+s+")"),t["mask-repeat"]=t["-webkit-mask-repeat"]="no-repeat",t["mask-size"]=t["-webkit-mask-size"]="100% 100%";break}return t}function O(e,t){const s={},n=t.varName;e.width!==e.height&&(t.forceSquare?e=A(e):s.width=j("1em",e.width/e.height));const a=$(e.body.replace(/currentColor/g,t.color||"black"),{viewBox:`${e.left} ${e.top} ${e.width} ${e.height}`,width:e.width.toString(),height:e.height.toString()}),r=T(a);if(n)s["--"+n]=r;else switch(t.mode){case"background":s["background-image"]=r;break;case"mask":s["mask-image"]=s["-webkit-mask-image"]=r;break}return s}const g={selectorStart:{compressed:"{",compact:" {",expanded:" {"},selectorEnd:{compressed:"}",compact:`; }
|
|
2
|
-
`,expanded:`;
|
|
3
|
-
}
|
|
4
|
-
`},rule:{compressed:"{key}:",compact:" {key}: ",expanded:`
|
|
5
|
-
{key}: `}};function E(e,t="expanded"){const s=[];for(let n=0;n<e.length;n++){const{selector:a,rules:r}=e[n];let c=(a instanceof Array?a.join(t==="compressed"?",":", "):a)+g.selectorStart[t],u=!0;for(const l in r)u||(c+=";"),c+=g.rule[t].replace("{key}",l)+r[l],u=!1;c+=g.selectorEnd[t],s.push(c)}return s.join(t==="compressed"?"":`
|
|
6
|
-
`)}function M(e,t={}){const s=t.customise?t.customise(e.body):e.body,n=t.mode||(t.color||!s.includes("currentColor")?"background":"mask");let a=t.varName;a===void 0&&n==="mask"&&(a="svg");const r={...t,mode:n,varName:a};n==="background"&&delete r.varName;const o={...t.rules,...L(r),...O({...y,...e,body:s},r)},c=t.iconSelector||".icon";return E([{selector:c,rules:o}],r.format)}async function W(e){return await new Promise(t=>b([e],()=>t(!0))).catch(()=>null),k(e)}function w(e){const t=m().icon,s=(t.collections||[]).sort((n,a)=>a.length-n.length);return d(()=>{var o;const n=e(),a=n.startsWith(t.cssSelectorPrefix)?n.slice(t.cssSelectorPrefix.length):n,r=((o=t.aliases)==null?void 0:o[a])||a;if(!r.includes(":")){const c=s.find(u=>r.startsWith(u+"-"));return c?c+":"+r.slice(c.length+1):r}return r})}let f;function F(e){return e.replace(/([^\w-])/g,"\\$1")}function D(){if(f)return f;f=new Set;const e=s=>{if(s=s.replace(/^:where\((.*)\)$/,"$1").trim(),s.startsWith("."))return s},t=s=>{if(s!=null&&s.length)for(const n of s){n!=null&&n.cssRules&&t(n.cssRules);const a=n==null?void 0:n.selectorText;if(typeof a=="string"){const r=e(a);r&&f.add(r)}}};for(let s=0;s<document.styleSheets.length;s++){const n=document.styleSheets[s].cssRules||document.styleSheets[s].rules;t(n)}return f}const H=h({name:"NuxtIconCss",props:{name:{type:String,required:!0}},async setup(e){const t=p(),s=m().icon,n=d(()=>s.cssSelectorPrefix+e.name);function a(c){const u=k(c);if(u)return u;const l=t.payload.data[c];if(l)return v(c,l),l}const r=d(()=>"."+F(n.value));function o(c,u=!0){let l=r.value;s.cssWherePseudo&&(l=`:where(${l})`);const i=M(c,{iconSelector:l,format:"compressed"});return s.cssLayer&&u?`@layer ${s.cssLayer} { ${i} }`:i}{const c=D();async function u(l){if(c.has(r.value))return;const i=document.createElement("style");i.textContent=o(l),document.head.prepend(i),c.add(r.value)}x(()=>e.name,()=>{if(c.has(r.value))return;const l=a(e.name);l?u(l):W(e.name).then(i=>{i&&u(i)})},{immediate:!0})}return()=>S("span",{class:["iconify",n.value,s.class]})}}),U=h({name:"NuxtIconSvg",props:{name:{type:String,required:!0}},async setup(e,{slots:t}){const s=p(),n=m().icon,a=w(()=>e.name),r="i-"+a.value;{const o=s.payload.data[r];o&&v(a.value,o)}return()=>S(N,{icon:a.value,ssr:!0,class:n.class},t)}}),G=h({name:"NuxtIcon",props:{name:{type:String,required:!0},mode:{type:String,required:!1,default:null},size:{type:[Number,String],required:!1,default:null}},async setup(e,{slots:t}){const s=p(),n=m().icon,a=w(()=>e.name),r=d(()=>{var c;return((c=s.vueApp)==null?void 0:c.component(a.value))||((e.mode||n.mode)==="svg"?U:H)}),o=d(()=>{const c=e.size||n.size;return c?{fontSize:Number.isNaN(+c)?c:c+"px"}:null});return()=>S(r.value,{...n.attrs,name:a.value,class:n.class,style:o.value},t)}});export{G as default};
|