vite-plugin-sitemap 0.9.0 → 0.10.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 CHANGED
@@ -168,13 +168,15 @@ Converts XML into a human readable format
168
168
 
169
169
  ### i18n
170
170
 
171
- - **Type:** `{ defaultLanguage?: string, languages: string[], strategy?: 'suffix' | 'prefix' }`
171
+ - **Type:** `{ defaultLanguage?: string, languages: string[], strategy?: 'suffix' | 'prefix' | 'prefix_except_default', includeDefaultLanguageInURL?: boolean }`
172
172
  - **Default:** `undefined, strategy: 'suffix'`
173
173
 
174
174
  Add i18n support defining alternate links.
175
175
  defaultLanguage will use this language with / and languages with /language.
176
176
  strategy specifies if the language code is a suffix to the path or a prefix. 'suffix' is default. Example: http://localhost/mypage/en or http://localhost/en/mypage
177
177
 
178
+ Set `includeDefaultLanguageInURL: true` to also apply the strategy to the default language. In that case, `<loc>`, the default-language alternate, and `x-default` all point to the localized URL (e.g. http://localhost/en/mypage instead of http://localhost/mypage). Useful when every page is served under a language prefix, as recommended by [Google](https://developers.google.com/search/docs/specialty/international/localized-versions#example_2).
179
+
178
180
  ### generateRobotsTxt
179
181
 
180
182
  - **Type:** `boolean`
package/dist/index.d.ts CHANGED
@@ -69,6 +69,16 @@ interface Options {
69
69
  defaultLanguage?: string;
70
70
  languages: string[];
71
71
  strategy?: 'suffix' | 'prefix' | 'prefix_except_default';
72
+ /**
73
+ * When true, the `<loc>` URL and the default-language alternate
74
+ * (and `x-default`) are built with the strategy applied to the
75
+ * default language too, producing URLs like `/<defaultLang>/route`
76
+ * (prefix) or `/route/<defaultLang>` (suffix).
77
+ * Only applies when `strategy` is 'prefix' or 'suffix' and
78
+ * `defaultLanguage` is set.
79
+ * @default false
80
+ */
81
+ includeDefaultLanguageInURL?: boolean;
72
82
  };
73
83
  /**
74
84
  * Other sitemaps paths
package/dist/index.js CHANGED
@@ -9224,17 +9224,22 @@ function getFormattedSitemap(options, routes) {
9224
9224
  };
9225
9225
  if (options.i18n) {
9226
9226
  const strategy = (_d = options.i18n.strategy) != null ? _d : "suffix";
9227
+ const buildLocalizedUrl = (lang) => new URL(strategy === "prefix" ? ensurePrefix("/", lang) + routePath : removeMaybeSuffix("/", routePath) + ensurePrefix("/", lang), hostNamePath).href;
9228
+ const includeDefault = options.i18n.includeDefaultLanguageInURL && !!options.i18n.defaultLanguage;
9229
+ const defaultLanguageUrl = includeDefault ? buildLocalizedUrl(options.i18n.defaultLanguage) : url;
9227
9230
  const languages = options.i18n.languages.map((str) => {
9228
9231
  var _a3;
9229
9232
  return {
9230
9233
  lang: str,
9231
- url: str === ((_a3 = options.i18n) == null ? void 0 : _a3.defaultLanguage) ? url : new URL(strategy === "prefix" ? ensurePrefix("/", str) + routePath : removeMaybeSuffix("/", routePath) + ensurePrefix("/", str), hostNamePath).href
9234
+ url: str === ((_a3 = options.i18n) == null ? void 0 : _a3.defaultLanguage) ? defaultLanguageUrl : buildLocalizedUrl(str)
9232
9235
  };
9233
9236
  });
9237
+ if (includeDefault)
9238
+ formattedSitemap.url = defaultLanguageUrl;
9234
9239
  return Object.assign(formattedSitemap, {
9235
9240
  links: options.i18n.defaultLanguage ? [
9236
9241
  ...languages,
9237
- { lang: "x-default", url }
9242
+ { lang: "x-default", url: defaultLanguageUrl }
9238
9243
  ] : languages
9239
9244
  });
9240
9245
  }
package/dist/index.mjs CHANGED
@@ -9224,17 +9224,22 @@ function getFormattedSitemap(options, routes) {
9224
9224
  };
9225
9225
  if (options.i18n) {
9226
9226
  const strategy = (_d = options.i18n.strategy) != null ? _d : "suffix";
9227
+ const buildLocalizedUrl = (lang) => new URL(strategy === "prefix" ? ensurePrefix("/", lang) + routePath : removeMaybeSuffix("/", routePath) + ensurePrefix("/", lang), hostNamePath).href;
9228
+ const includeDefault = options.i18n.includeDefaultLanguageInURL && !!options.i18n.defaultLanguage;
9229
+ const defaultLanguageUrl = includeDefault ? buildLocalizedUrl(options.i18n.defaultLanguage) : url;
9227
9230
  const languages = options.i18n.languages.map((str) => {
9228
9231
  var _a3;
9229
9232
  return {
9230
9233
  lang: str,
9231
- url: str === ((_a3 = options.i18n) == null ? void 0 : _a3.defaultLanguage) ? url : new URL(strategy === "prefix" ? ensurePrefix("/", str) + routePath : removeMaybeSuffix("/", routePath) + ensurePrefix("/", str), hostNamePath).href
9234
+ url: str === ((_a3 = options.i18n) == null ? void 0 : _a3.defaultLanguage) ? defaultLanguageUrl : buildLocalizedUrl(str)
9232
9235
  };
9233
9236
  });
9237
+ if (includeDefault)
9238
+ formattedSitemap.url = defaultLanguageUrl;
9234
9239
  return Object.assign(formattedSitemap, {
9235
9240
  links: options.i18n.defaultLanguage ? [
9236
9241
  ...languages,
9237
- { lang: "x-default", url }
9242
+ { lang: "x-default", url: defaultLanguageUrl }
9238
9243
  ] : languages
9239
9244
  });
9240
9245
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-sitemap",
3
3
  "type": "module",
4
- "version": "0.9.0",
4
+ "version": "0.10.0",
5
5
  "packageManager": "pnpm@12.21.0",
6
6
  "description": "Sitemap generator plugin for Vite",
7
7
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "eslint-plugin-format": "^2.0.1",
37
37
  "pkgroll": "^2.29.1",
38
38
  "pnpm": "^12.21.0",
39
- "sitemap-ts": "^2.2.0",
39
+ "sitemap-ts": "^2.3.1",
40
40
  "taze": "^21.3.0",
41
41
  "typescript": "^6.0.3",
42
42
  "vite": "^8.3.8",