vite-plugin-sitemap 0.5.1 → 0.5.3

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
@@ -94,6 +94,18 @@ export default {
94
94
 
95
95
  You can find a working example in example folder.
96
96
 
97
+ ### externalSitemaps
98
+
99
+ - **Type:** `string[]`
100
+ - **Default:** `[]`
101
+
102
+ Array of strings with other sitemaps paths or urls.
103
+ ```js
104
+ generateSitemap({
105
+ externalSitemaps: ['sitemap_1', 'sitemap_2', 'subpath/sitemap_3', 'https://site.com/sitemap.xml']
106
+ })
107
+ ```
108
+
97
109
  ### outDir
98
110
 
99
111
  - **Type:** `string`
package/dist/index.d.ts CHANGED
@@ -49,6 +49,12 @@ interface Options {
49
49
  * @default []
50
50
  */
51
51
  exclude: string[];
52
+ /**
53
+ * Other sitemaps paths
54
+ * Example: ['sitemap_1.xml', 'path/sitemap_2.xml', 'https://site.com/sitemap.xml']
55
+ * @default []
56
+ */
57
+ externalSitemaps: string[];
52
58
  /**
53
59
  * String with base path.
54
60
  * Example: '/mysubpath'
package/dist/index.js CHANGED
@@ -4154,11 +4154,6 @@ function ensurePrefix(prefix, str) {
4154
4154
  return prefix + str;
4155
4155
  return str;
4156
4156
  }
4157
- function ensureSuffix(suffix, str) {
4158
- if (!str.endsWith(suffix))
4159
- return str + suffix;
4160
- return str;
4161
- }
4162
4157
 
4163
4158
  var tasks = {};
4164
4159
 
@@ -10859,6 +10854,7 @@ const defaultOptions = {
10859
10854
  hostname: "http://localhost/",
10860
10855
  dynamicRoutes: [],
10861
10856
  exclude: [],
10857
+ externalSitemaps: [],
10862
10858
  basePath: "",
10863
10859
  outDir: "dist",
10864
10860
  extensions: "html",
@@ -10880,6 +10876,17 @@ function resolveOptions(userOptions) {
10880
10876
  );
10881
10877
  }
10882
10878
 
10879
+ function getResolvedPath(file, resolvedOptions) {
10880
+ if (node_path.isAbsolute(resolvedOptions.outDir))
10881
+ return node_path.resolve(`${resolvedOptions.outDir}/${file}`);
10882
+ return node_path.resolve(`${ensurePrefix("./", resolvedOptions.outDir)}/${file}`);
10883
+ }
10884
+ function removeMaybeSuffix(suffix, str) {
10885
+ if (!str.endsWith(suffix))
10886
+ return str;
10887
+ return str.slice(0, -suffix.length);
10888
+ }
10889
+
10883
10890
  var RobotCorrespondences = /* @__PURE__ */ ((RobotCorrespondences2) => {
10884
10891
  RobotCorrespondences2["userAgent"] = "User-agent";
10885
10892
  RobotCorrespondences2["allow"] = "Allow";
@@ -10904,24 +10911,14 @@ function getRules(options) {
10904
10911
  });
10905
10912
  return rules;
10906
10913
  }
10907
- function getContent(rules, hostname) {
10914
+ function getContent(rules, hostname, externalSitemaps) {
10908
10915
  return rules.map((rule) => `${rule.key}: ${String(rule.value).trim()}`).join("\n").concat(`
10909
10916
 
10910
- Sitemap: ${getFinalSitemapPath(hostname)}`);
10911
- }
10912
- function getFinalSitemapPath(hostname) {
10913
- return `${ensureSuffix("/", hostname)}sitemap.xml`;
10914
- }
10915
-
10916
- function getResolvedPath(file, resolvedOptions) {
10917
- if (node_path.isAbsolute(resolvedOptions.outDir))
10918
- return node_path.resolve(`${resolvedOptions.outDir}/${file}`);
10919
- return node_path.resolve(`${ensurePrefix("./", resolvedOptions.outDir)}/${file}`);
10917
+ Sitemap: ${getFinalSitemapPath(hostname)}`).concat(externalSitemaps.map((s) => `
10918
+ Sitemap: ${s.startsWith("http") ? s : getFinalSitemapPath(hostname, s)}`).join(""));
10920
10919
  }
10921
- function removeMaybeSuffix(suffix, str) {
10922
- if (!str.endsWith(suffix))
10923
- return str;
10924
- return str.slice(0, -suffix.length);
10920
+ function getFinalSitemapPath(hostname, file = "/sitemap.xml") {
10921
+ return `${removeMaybeSuffix("/", hostname)}${ensurePrefix("/", file)}`;
10925
10922
  }
10926
10923
 
10927
10924
  function getRoutes(options) {
@@ -10963,7 +10960,7 @@ function generateSitemap(options = {}) {
10963
10960
  const resolvedOptions = resolveOptions(options);
10964
10961
  if (resolvedOptions.generateRobotsTxt) {
10965
10962
  const robotRules = getRules(resolvedOptions.robots);
10966
- const robotContent = getContent(robotRules, resolvedOptions.hostname);
10963
+ const robotContent = getContent(robotRules, resolvedOptions.hostname, resolvedOptions.externalSitemaps);
10967
10964
  node_fs.writeFileSync(getResolvedPath("robots.txt", resolvedOptions), robotContent);
10968
10965
  }
10969
10966
  const routes = getRoutes(resolvedOptions);
package/dist/index.mjs CHANGED
@@ -4151,11 +4151,6 @@ function ensurePrefix(prefix, str) {
4151
4151
  return prefix + str;
4152
4152
  return str;
4153
4153
  }
4154
- function ensureSuffix(suffix, str) {
4155
- if (!str.endsWith(suffix))
4156
- return str + suffix;
4157
- return str;
4158
- }
4159
4154
 
4160
4155
  var tasks = {};
4161
4156
 
@@ -10856,6 +10851,7 @@ const defaultOptions = {
10856
10851
  hostname: "http://localhost/",
10857
10852
  dynamicRoutes: [],
10858
10853
  exclude: [],
10854
+ externalSitemaps: [],
10859
10855
  basePath: "",
10860
10856
  outDir: "dist",
10861
10857
  extensions: "html",
@@ -10877,6 +10873,17 @@ function resolveOptions(userOptions) {
10877
10873
  );
10878
10874
  }
10879
10875
 
10876
+ function getResolvedPath(file, resolvedOptions) {
10877
+ if (isAbsolute(resolvedOptions.outDir))
10878
+ return resolve(`${resolvedOptions.outDir}/${file}`);
10879
+ return resolve(`${ensurePrefix("./", resolvedOptions.outDir)}/${file}`);
10880
+ }
10881
+ function removeMaybeSuffix(suffix, str) {
10882
+ if (!str.endsWith(suffix))
10883
+ return str;
10884
+ return str.slice(0, -suffix.length);
10885
+ }
10886
+
10880
10887
  var RobotCorrespondences = /* @__PURE__ */ ((RobotCorrespondences2) => {
10881
10888
  RobotCorrespondences2["userAgent"] = "User-agent";
10882
10889
  RobotCorrespondences2["allow"] = "Allow";
@@ -10901,24 +10908,14 @@ function getRules(options) {
10901
10908
  });
10902
10909
  return rules;
10903
10910
  }
10904
- function getContent(rules, hostname) {
10911
+ function getContent(rules, hostname, externalSitemaps) {
10905
10912
  return rules.map((rule) => `${rule.key}: ${String(rule.value).trim()}`).join("\n").concat(`
10906
10913
 
10907
- Sitemap: ${getFinalSitemapPath(hostname)}`);
10908
- }
10909
- function getFinalSitemapPath(hostname) {
10910
- return `${ensureSuffix("/", hostname)}sitemap.xml`;
10911
- }
10912
-
10913
- function getResolvedPath(file, resolvedOptions) {
10914
- if (isAbsolute(resolvedOptions.outDir))
10915
- return resolve(`${resolvedOptions.outDir}/${file}`);
10916
- return resolve(`${ensurePrefix("./", resolvedOptions.outDir)}/${file}`);
10914
+ Sitemap: ${getFinalSitemapPath(hostname)}`).concat(externalSitemaps.map((s) => `
10915
+ Sitemap: ${s.startsWith("http") ? s : getFinalSitemapPath(hostname, s)}`).join(""));
10917
10916
  }
10918
- function removeMaybeSuffix(suffix, str) {
10919
- if (!str.endsWith(suffix))
10920
- return str;
10921
- return str.slice(0, -suffix.length);
10917
+ function getFinalSitemapPath(hostname, file = "/sitemap.xml") {
10918
+ return `${removeMaybeSuffix("/", hostname)}${ensurePrefix("/", file)}`;
10922
10919
  }
10923
10920
 
10924
10921
  function getRoutes(options) {
@@ -10960,7 +10957,7 @@ function generateSitemap(options = {}) {
10960
10957
  const resolvedOptions = resolveOptions(options);
10961
10958
  if (resolvedOptions.generateRobotsTxt) {
10962
10959
  const robotRules = getRules(resolvedOptions.robots);
10963
- const robotContent = getContent(robotRules, resolvedOptions.hostname);
10960
+ const robotContent = getContent(robotRules, resolvedOptions.hostname, resolvedOptions.externalSitemaps);
10964
10961
  writeFileSync(getResolvedPath("robots.txt", resolvedOptions), robotContent);
10965
10962
  }
10966
10963
  const routes = getRoutes(resolvedOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-sitemap",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "packageManager": "pnpm@8.9.2",
5
5
  "description": "Sitemap generator plugin for Vite",
6
6
  "main": "dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "eslint": "8.51.0",
25
25
  "pkgroll": "2.0.1",
26
26
  "pnpm": "8.9.2",
27
- "sitemap-ts": "1.5.0",
27
+ "sitemap-ts": "1.6.1",
28
28
  "typescript": "5.2.2",
29
29
  "vite": "4.5.0",
30
30
  "vite-plugin-pages": "0.31.0",