@nuxtjs/sitemap 8.1.0 → 8.2.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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "nuxt": ">=3.9.0"
5
5
  },
6
6
  "configKey": "sitemap",
7
- "version": "8.1.0",
7
+ "version": "8.2.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -75,6 +75,7 @@ export async function readSourcesFromFilesystem(filename) {
75
75
  if (!route.fileName?.endsWith(".html") || !html || ["/200.html", "/404.html"].includes(route.route))
76
76
  return;
77
77
  if (NuxtRedirectHtmlRegex.test(html)) {
78
+ route._sitemap = { loc: route.route, _sitemap: false };
78
79
  return;
79
80
  }
80
81
  const extractedMeta = parseHtmlExtractSitemapMeta(html, {
@@ -1128,7 +1129,13 @@ ${onUrlEntries.join("\n")}`;
1128
1129
  const nitro = await nitroPromise;
1129
1130
  const prerenderedRoutes2 = nitro._prerenderedRoutes || [];
1130
1131
  const prerenderUrlsFinal = [
1131
- ...prerenderedRoutes2.filter(isValidPrerenderRoute).map((r) => r._sitemap).filter((entry) => entry && (typeof entry === "string" || entry._sitemap !== false))
1132
+ ...prerenderedRoutes2.filter(isValidPrerenderRoute).map((r) => {
1133
+ if (r._sitemap)
1134
+ return r._sitemap;
1135
+ if (r.route.startsWith("/api/") || r.route.startsWith("/_"))
1136
+ return void 0;
1137
+ return { loc: r.route };
1138
+ }).filter((entry) => entry && (typeof entry === "string" || entry._sitemap !== false))
1132
1139
  ];
1133
1140
  if (config.debug) {
1134
1141
  logger.info("Prerendered routes:", prerenderUrlsFinal);
@@ -3,7 +3,7 @@ import { defineCachedFunction, useRuntimeConfig } from "nitropack/runtime";
3
3
  import { resolveSitePath } from "nuxt-site-config/urls";
4
4
  import { joinURL, withHttps } from "ufo";
5
5
  import staticConfig from "#sitemap-virtual/static-config.mjs";
6
- import { applyDynamicParams, createPathFilter, findPageMapping, logger, splitForLocales } from "../../../utils-pure.js";
6
+ import { applyDynamicParams, createPathFilter, findPageMapping, logger, resolveI18nSitemapLocaleKey, splitForLocales } from "../../../utils-pure.js";
7
7
  import { preNormalizeEntry } from "../urlset/normalise.js";
8
8
  import { sortInPlace } from "../urlset/sort.js";
9
9
  import { childSitemapSources, globalSitemapSources, resolveSitemapSources } from "../urlset/sources.js";
@@ -189,11 +189,12 @@ export async function buildResolvedSitemapUrls(effectiveSitemap, matchName, isCh
189
189
  };
190
190
  await nitro?.hooks.callHook("sitemap:input", resolvedCtx);
191
191
  const enhancedUrls = resolveSitemapEntries(effectiveSitemap, resolvedCtx.urls, { autoI18n, isI18nMapped }, resolvers, useRuntimeConfig().app.baseURL);
192
+ const localeSitemapKeys = isI18nMapped && autoI18n ? autoI18n.locales.map((l) => l._sitemap) : [];
192
193
  if (isMultiSitemap) {
193
194
  const sitemapNames = Object.keys(sitemaps).filter((k) => k !== "index");
194
195
  const warnedSitemaps = nitro?._sitemapWarnedSitemaps || /* @__PURE__ */ new Set();
195
196
  for (const e of enhancedUrls) {
196
- const hasMatchingSitemap = typeof e._sitemap === "string" && (sitemapNames.includes(e._sitemap) || isI18nMapped && sitemapNames.some((name) => name.startsWith(`${e._sitemap}-`)));
197
+ const hasMatchingSitemap = typeof e._sitemap === "string" && (sitemapNames.includes(e._sitemap) || isI18nMapped && sitemapNames.some((name) => resolveI18nSitemapLocaleKey(name, localeSitemapKeys) === e._sitemap));
197
198
  if (typeof e._sitemap === "string" && !hasMatchingSitemap) {
198
199
  if (!warnedSitemaps.has(e._sitemap)) {
199
200
  warnedSitemaps.add(e._sitemap);
@@ -211,7 +212,11 @@ export async function buildResolvedSitemapUrls(effectiveSitemap, matchName, isCh
211
212
  if (isMultiSitemap && e._sitemap && matchName) {
212
213
  if (isChunked)
213
214
  return e._sitemap === matchName;
214
- return e._sitemap === matchName || isI18nMapped && matchName.startsWith(`${e._sitemap}-`);
215
+ if (e._sitemap === matchName)
216
+ return true;
217
+ if (isI18nMapped)
218
+ return e._sitemap === resolveI18nSitemapLocaleKey(matchName, localeSitemapKeys);
219
+ return false;
215
220
  }
216
221
  return true;
217
222
  });
@@ -3,6 +3,16 @@ export { createFilter, type CreateFilterOptions } from 'nuxtseo-shared/utils';
3
3
  export declare const logger: import("consola").ConsolaInstance;
4
4
  export declare function mergeOnKey<T, K extends keyof T>(arr: T[], key: K): T[];
5
5
  export declare function splitForLocales(path: string, locales: string[]): [string | null, string];
6
+ /**
7
+ * Resolve which locale a multi-sitemap name belongs to.
8
+ *
9
+ * i18n-mapped sitemaps are named either `<localeSitemap>` (default) or
10
+ * `<localeSitemap>-<name>` (custom sitemaps). Locale `_sitemap` keys can share a
11
+ * prefix (e.g. `zh` and `zh-Hant`), so a naive `name.startsWith(`${key}-`)` check
12
+ * collides: `zh-Hant` would match the `zh` locale. Resolve by the longest matching
13
+ * key to disambiguate.
14
+ */
15
+ export declare function resolveI18nSitemapLocaleKey(sitemapName: string, localeSitemapKeys: string[]): string | null;
6
16
  /**
7
17
  * Transform a literal notation string regex to RegExp
8
18
  */
@@ -36,6 +36,16 @@ export function splitForLocales(path, locales) {
36
36
  return [prefix, path.replace(`/${prefix}`, "")];
37
37
  return [null, path];
38
38
  }
39
+ export function resolveI18nSitemapLocaleKey(sitemapName, localeSitemapKeys) {
40
+ let best = null;
41
+ for (const key of localeSitemapKeys) {
42
+ if (sitemapName === key || sitemapName.startsWith(`${key}-`)) {
43
+ if (best === null || key.length > best.length)
44
+ best = key;
45
+ }
46
+ }
47
+ return best;
48
+ }
39
49
  const StringifiedRegExpPattern = /\/(.*?)\/([gimsuy]*)$/;
40
50
  export function normalizeRuntimeFilters(input) {
41
51
  return (input || []).map((rule) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxtjs/sitemap",
3
3
  "type": "module",
4
- "version": "8.1.0",
4
+ "version": "8.2.0",
5
5
  "description": "Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -55,12 +55,12 @@
55
55
  }
56
56
  },
57
57
  "dependencies": {
58
- "@nuxt/kit": "^4.4.7",
58
+ "@nuxt/kit": "^4.4.8",
59
59
  "consola": "^3.4.2",
60
60
  "defu": "^6.1.7",
61
61
  "fast-xml-parser": "^5.8.0",
62
62
  "nuxt-site-config": "^4.0.8",
63
- "nuxtseo-shared": "^5.1.4",
63
+ "nuxtseo-shared": "^5.2.6",
64
64
  "ofetch": "^1.5.1",
65
65
  "pathe": "^2.0.3",
66
66
  "pkg-types": "^2.3.1",
@@ -85,10 +85,10 @@
85
85
  "eslint-plugin-harlanzw": "^0.17.0",
86
86
  "execa": "^9.6.1",
87
87
  "happy-dom": "^20.10.2",
88
- "nuxt": "^4.4.7",
88
+ "nuxt": "^4.4.8",
89
89
  "nuxt-i18n-micro": "^3.18.2",
90
- "nuxtseo-layer-devtools": "^5.1.4",
91
- "semver": "^7.8.3",
90
+ "nuxtseo-layer-devtools": "^5.2.6",
91
+ "semver": "^7.8.4",
92
92
  "sirv": "^3.0.2",
93
93
  "std-env": "^4.1.0",
94
94
  "typescript": "^6.0.3",
@@ -96,18 +96,17 @@
96
96
  "vitest": "^4.1.8",
97
97
  "vue-tsc": "^3.3.4",
98
98
  "zod": "^4.4.3",
99
- "@nuxtjs/sitemap": "8.1.0"
99
+ "@nuxtjs/sitemap": "8.2.0"
100
100
  },
101
101
  "scripts": {
102
102
  "lint": "eslint .",
103
103
  "lint:fix": "eslint . --fix",
104
- "client:build": "nuxt generate devtools",
105
- "devtools": "nuxt dev devtools --port 3030",
104
+ "client:build": "node -e \"require('fs').cpSync('devtools','dist/devtools',{recursive:true})\"",
106
105
  "build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build && npm run client:build",
107
106
  "dev": "nuxt dev playground",
108
107
  "prepare:fixtures": "nuxt prepare test/fixtures/basic && nuxt prepare test/fixtures/i18n && nuxt prepare test/fixtures/i18n-micro",
109
108
  "dev:build": "nuxt build playground",
110
- "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
109
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground && pnpm run client:build",
111
110
  "release": "pnpm build && bumpp -x \"npx changelogen --output=CHANGELOG.md\"",
112
111
  "test": "vitest run && pnpm run test:attw",
113
112
  "test:unit": "vitest --project=unit",