vite-plugin-sitemap 0.7.0 → 0.7.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/index.d.ts CHANGED
@@ -54,12 +54,14 @@ interface Options {
54
54
  * Example: {
55
55
  * defaultLanguage: 'fr'
56
56
  * languages: ['fr', 'en', 'es']
57
+ * strategy: 'suffix' | 'prefix'
57
58
  * }
58
- * @default undefined
59
+ * @default undefined, strategy: 'suffix'
59
60
  */
60
61
  i18n?: {
61
62
  defaultLanguage?: string;
62
63
  languages: string[];
64
+ strategy?: 'suffix' | 'prefix';
63
65
  };
64
66
  /**
65
67
  * Other sitemaps paths
package/dist/index.js CHANGED
@@ -10998,6 +10998,8 @@ function assertPatternsInput(input) {
10998
10998
  }
10999
10999
  var out = FastGlob;
11000
11000
 
11001
+ var fg = /*@__PURE__*/getDefaultExportFromCjs(out);
11002
+
11001
11003
  const defaultOptions = {
11002
11004
  hostname: "http://localhost/",
11003
11005
  dynamicRoutes: [],
@@ -11073,7 +11075,7 @@ function getRoutes(options) {
11073
11075
  const ext = typeof options.extensions === "string" ? [options.extensions] : options.extensions;
11074
11076
  const strExt = ext.map((e) => `**/*.${e}`);
11075
11077
  return [
11076
- ...out.sync(strExt, { cwd: options.outDir }).map((route) => {
11078
+ ...fg.sync(strExt, { cwd: options.outDir }).map((route) => {
11077
11079
  let r = route;
11078
11080
  ext.forEach((e) => {
11079
11081
  const regex = new RegExp(`index.${e}`, "g");
@@ -11097,7 +11099,9 @@ function getOptionByRoute(options, route) {
11097
11099
  }
11098
11100
  function getFormattedSitemap(options, routes) {
11099
11101
  return routes.map((route) => {
11100
- const url = new URL(options.basePath ? ensurePrefix("/", options.basePath) + ensurePrefix("/", route) : ensurePrefix("/", route), removeMaybeSuffix("/", options.hostname)).href;
11102
+ const hostNamePath = removeMaybeSuffix("/", options.hostname);
11103
+ const routePath = options.basePath ? ensurePrefix("/", options.basePath) + ensurePrefix("/", route) : ensurePrefix("/", route);
11104
+ const url = new URL(routePath, hostNamePath).href;
11101
11105
  const formattedSitemap = {
11102
11106
  url,
11103
11107
  changefreq: getOptionByRoute(options.changefreq, route) ?? defaultOptions.changefreq,
@@ -11105,9 +11109,10 @@ function getFormattedSitemap(options, routes) {
11105
11109
  lastmod: getOptionByRoute(options.lastmod, route) ?? defaultOptions.lastmod
11106
11110
  };
11107
11111
  if (options.i18n) {
11112
+ const strategy = options.i18n.strategy ?? "suffix";
11108
11113
  const languages = options.i18n.languages.map((str) => ({
11109
11114
  lang: str,
11110
- url: str === options.i18n?.defaultLanguage ? url : `${removeMaybeSuffix("/", url)}${ensurePrefix("/", str)}`
11115
+ url: str === options.i18n?.defaultLanguage ? url : new URL(strategy === "prefix" ? ensurePrefix("/", str) + routePath : removeMaybeSuffix("/", routePath) + ensurePrefix("/", str), hostNamePath).href
11111
11116
  }));
11112
11117
  return Object.assign(formattedSitemap, { links: options.i18n.defaultLanguage ? [...languages, { lang: "x-default", url }] : languages });
11113
11118
  }
package/dist/index.mjs CHANGED
@@ -10998,6 +10998,8 @@ function assertPatternsInput(input) {
10998
10998
  }
10999
10999
  var out = FastGlob;
11000
11000
 
11001
+ var fg = /*@__PURE__*/getDefaultExportFromCjs(out);
11002
+
11001
11003
  const defaultOptions = {
11002
11004
  hostname: "http://localhost/",
11003
11005
  dynamicRoutes: [],
@@ -11073,7 +11075,7 @@ function getRoutes(options) {
11073
11075
  const ext = typeof options.extensions === "string" ? [options.extensions] : options.extensions;
11074
11076
  const strExt = ext.map((e) => `**/*.${e}`);
11075
11077
  return [
11076
- ...out.sync(strExt, { cwd: options.outDir }).map((route) => {
11078
+ ...fg.sync(strExt, { cwd: options.outDir }).map((route) => {
11077
11079
  let r = route;
11078
11080
  ext.forEach((e) => {
11079
11081
  const regex = new RegExp(`index.${e}`, "g");
@@ -11097,7 +11099,9 @@ function getOptionByRoute(options, route) {
11097
11099
  }
11098
11100
  function getFormattedSitemap(options, routes) {
11099
11101
  return routes.map((route) => {
11100
- const url = new URL(options.basePath ? ensurePrefix("/", options.basePath) + ensurePrefix("/", route) : ensurePrefix("/", route), removeMaybeSuffix("/", options.hostname)).href;
11102
+ const hostNamePath = removeMaybeSuffix("/", options.hostname);
11103
+ const routePath = options.basePath ? ensurePrefix("/", options.basePath) + ensurePrefix("/", route) : ensurePrefix("/", route);
11104
+ const url = new URL(routePath, hostNamePath).href;
11101
11105
  const formattedSitemap = {
11102
11106
  url,
11103
11107
  changefreq: getOptionByRoute(options.changefreq, route) ?? defaultOptions.changefreq,
@@ -11105,9 +11109,10 @@ function getFormattedSitemap(options, routes) {
11105
11109
  lastmod: getOptionByRoute(options.lastmod, route) ?? defaultOptions.lastmod
11106
11110
  };
11107
11111
  if (options.i18n) {
11112
+ const strategy = options.i18n.strategy ?? "suffix";
11108
11113
  const languages = options.i18n.languages.map((str) => ({
11109
11114
  lang: str,
11110
- url: str === options.i18n?.defaultLanguage ? url : `${removeMaybeSuffix("/", url)}${ensurePrefix("/", str)}`
11115
+ url: str === options.i18n?.defaultLanguage ? url : new URL(strategy === "prefix" ? ensurePrefix("/", str) + routePath : removeMaybeSuffix("/", routePath) + ensurePrefix("/", str), hostNamePath).href
11111
11116
  }));
11112
11117
  return Object.assign(formattedSitemap, { links: options.i18n.defaultLanguage ? [...languages, { lang: "x-default", url }] : languages });
11113
11118
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-sitemap",
3
3
  "type": "module",
4
- "version": "0.7.0",
4
+ "version": "0.7.1",
5
5
  "packageManager": "pnpm@9.1.2",
6
6
  "description": "Sitemap generator plugin for Vite",
7
7
  "main": "dist/index.js",