vite-plugin-sitemap 0.9.0 → 0.11.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 +26 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.js +7 -2
- package/dist/index.mjs +7 -2
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -78,6 +78,29 @@ export default {
|
|
|
78
78
|
|
|
79
79
|
You can find a working example in example folder.
|
|
80
80
|
|
|
81
|
+
For Vue Router v5+ (or [unplugin-vue-router](https://uvr.esm.is/)) with file-based routing, use the `getRoutesFromTypedRouter` helper re-exported by `sitemap-ts` to auto-discover static routes from the generated `typed-router.d.ts`:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import { fileURLToPath } from 'node:url'
|
|
85
|
+
import { getRoutesFromTypedRouter } from 'sitemap-ts'
|
|
86
|
+
import Sitemap from 'vite-plugin-sitemap'
|
|
87
|
+
|
|
88
|
+
const typedRouterFile = fileURLToPath(new URL('./typed-router.d.ts', import.meta.url))
|
|
89
|
+
|
|
90
|
+
export default {
|
|
91
|
+
plugins: [
|
|
92
|
+
Sitemap({
|
|
93
|
+
dynamicRoutes: [
|
|
94
|
+
...getRoutesFromTypedRouter(typedRouterFile),
|
|
95
|
+
...names.map(name => `/names/${name}`),
|
|
96
|
+
],
|
|
97
|
+
}),
|
|
98
|
+
],
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Dynamic routes (`/:param`, `*`) are filtered out by default — expand them to concrete values yourself. Pass `{ includeDynamic: true }` to keep them as patterns.
|
|
103
|
+
|
|
81
104
|
### exclude
|
|
82
105
|
|
|
83
106
|
- **Type:** `string[]`
|
|
@@ -168,13 +191,15 @@ Converts XML into a human readable format
|
|
|
168
191
|
|
|
169
192
|
### i18n
|
|
170
193
|
|
|
171
|
-
- **Type:** `{ defaultLanguage?: string, languages: string[], strategy?: 'suffix' | 'prefix' }`
|
|
194
|
+
- **Type:** `{ defaultLanguage?: string, languages: string[], strategy?: 'suffix' | 'prefix' | 'prefix_except_default', includeDefaultLanguageInURL?: boolean }`
|
|
172
195
|
- **Default:** `undefined, strategy: 'suffix'`
|
|
173
196
|
|
|
174
197
|
Add i18n support defining alternate links.
|
|
175
198
|
defaultLanguage will use this language with / and languages with /language.
|
|
176
199
|
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
200
|
|
|
201
|
+
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).
|
|
202
|
+
|
|
178
203
|
### generateRobotsTxt
|
|
179
204
|
|
|
180
205
|
- **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) ?
|
|
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) ?
|
|
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.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"packageManager": "pnpm@12.21.0",
|
|
6
6
|
"description": "Sitemap generator plugin for Vite",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,11 +36,10 @@
|
|
|
36
36
|
"eslint-plugin-format": "^2.0.1",
|
|
37
37
|
"pkgroll": "^2.29.1",
|
|
38
38
|
"pnpm": "^12.21.0",
|
|
39
|
-
"sitemap-ts": "^2.
|
|
39
|
+
"sitemap-ts": "^2.4.0",
|
|
40
40
|
"taze": "^21.3.0",
|
|
41
41
|
"typescript": "^6.0.3",
|
|
42
42
|
"vite": "^8.3.8",
|
|
43
|
-
"vite-plugin-pages": "^0.33.3",
|
|
44
43
|
"vue-tsc": "^3.3.14"
|
|
45
44
|
}
|
|
46
45
|
}
|