vite-plugin-sitemap 0.6.2 → 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/README.md +4 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -3
- package/dist/index.mjs +8 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -161,11 +161,12 @@ Converts XML into a human readable format
|
|
|
161
161
|
|
|
162
162
|
### i18n
|
|
163
163
|
|
|
164
|
-
- **Type:** `{ defaultLanguage?: string, languages: string[] }`
|
|
165
|
-
- **Default:** `undefined`
|
|
164
|
+
- **Type:** `{ defaultLanguage?: string, languages: string[], strategy?: 'suffix' | 'prefix' }`
|
|
165
|
+
- **Default:** `undefined, strategy: 'suffix'`
|
|
166
166
|
|
|
167
167
|
Add i18n support defining alternate links.
|
|
168
|
-
defaultLanguage will use this language with / and languages with /language
|
|
168
|
+
defaultLanguage will use this language with / and languages with /language.
|
|
169
|
+
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
|
|
169
170
|
|
|
170
171
|
### generateRobotsTxt
|
|
171
172
|
|
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
|
-
...
|
|
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
|
|
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 :
|
|
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
|
-
...
|
|
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
|
|
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 :
|
|
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.
|
|
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",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"eslint-plugin-format": "^0.1.1",
|
|
28
28
|
"pkgroll": "^2.1.1",
|
|
29
29
|
"pnpm": "^9.1.2",
|
|
30
|
-
"sitemap-ts": "^1.
|
|
30
|
+
"sitemap-ts": "^1.8.0",
|
|
31
31
|
"taze": "^0.13.8",
|
|
32
32
|
"typescript": "^5.4.5",
|
|
33
33
|
"vite": "^5.2.11",
|