vite-plugin-sitemap-ts 1.1.3 → 1.2.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 +48 -5
- package/dist/index.cjs +9 -2
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +9 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ sitemap({
|
|
|
41
41
|
hostname: 'https://example.com',
|
|
42
42
|
})
|
|
43
43
|
```
|
|
44
|
+
|
|
44
45
|
*Output:*
|
|
45
46
|
```xml
|
|
46
47
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -62,6 +63,7 @@ sitemap({
|
|
|
62
63
|
routes: ['/about'],
|
|
63
64
|
})
|
|
64
65
|
```
|
|
66
|
+
|
|
65
67
|
*Output:*
|
|
66
68
|
```xml
|
|
67
69
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -73,13 +75,54 @@ sitemap({
|
|
|
73
75
|
</urlset>
|
|
74
76
|
```
|
|
75
77
|
|
|
78
|
+
### With route objects:
|
|
79
|
+
|
|
80
|
+
Route objects (aka. `SitemapEntry` objects) allow for full control over "loc", "lastmod", "changefreq" and "priority".
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
sitemap({
|
|
84
|
+
hostname: 'https://example.com',
|
|
85
|
+
routes: [
|
|
86
|
+
'/',
|
|
87
|
+
'/about',
|
|
88
|
+
{
|
|
89
|
+
loc: '/blog',
|
|
90
|
+
lastmod: '2026-01-01',
|
|
91
|
+
changefreq: 'weekly',
|
|
92
|
+
priority: 0.8
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
*Output:*
|
|
99
|
+
```xml
|
|
100
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
101
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
102
|
+
<url>
|
|
103
|
+
<loc>https://example.com/</loc>
|
|
104
|
+
<lastmod>2026-03-14T20:31:12.450Z</lastmod>
|
|
105
|
+
</url>
|
|
106
|
+
<url>
|
|
107
|
+
<loc>https://example.com/about</loc>
|
|
108
|
+
<lastmod>2026-03-14T20:31:12.450Z</lastmod>
|
|
109
|
+
</url>
|
|
110
|
+
<url>
|
|
111
|
+
<loc>https://example.com/blog</loc>
|
|
112
|
+
<lastmod>2026-01-01</lastmod>
|
|
113
|
+
<changefreq>weekly</changefreq>
|
|
114
|
+
<priority>0.8</priority>
|
|
115
|
+
</url>
|
|
116
|
+
</urlset>
|
|
117
|
+
```
|
|
118
|
+
|
|
76
119
|
## Options
|
|
77
120
|
|
|
78
121
|
The `hostname` option is required. All other options are optional.
|
|
79
122
|
|
|
80
|
-
| Option | Type
|
|
81
|
-
|
|
82
|
-
| hostname | *string*
|
|
83
|
-
| enabled | *boolean*
|
|
84
|
-
| routes | *string[]* | `['/']` | An array of routes to include in the sitemap |
|
|
123
|
+
| Option | Type | Default | Description |
|
|
124
|
+
|----------|------------------------------|---------|----------------------------------------------------------------------|
|
|
125
|
+
| hostname | *string* | - | The hostname of the site, used to build the full URLs in the sitemap |
|
|
126
|
+
| enabled | *boolean* | `true` | Toggle the plugin on or off |
|
|
127
|
+
| routes | *(string \| [SitemapEntry](./src/types.ts#L3))[]* | `['/']` | An array of routes to include in the sitemap |
|
|
85
128
|
|
package/dist/index.cjs
CHANGED
|
@@ -91,9 +91,16 @@ var buildSitemapEntries = (options) => {
|
|
|
91
91
|
const host = options.hostname.replace(/\/$/, "");
|
|
92
92
|
const lastmod = (/* @__PURE__ */ new Date()).toISOString();
|
|
93
93
|
return options.routes.map((route) => {
|
|
94
|
+
if (typeof route === "string") {
|
|
95
|
+
return {
|
|
96
|
+
loc: `${host}/${route.replace(/^\/+/, "")}`,
|
|
97
|
+
lastmod
|
|
98
|
+
};
|
|
99
|
+
}
|
|
94
100
|
return {
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
...route,
|
|
102
|
+
loc: `${host}/${route.loc.replace(/^\/+/, "")}`,
|
|
103
|
+
lastmod: route.lastmod ?? lastmod
|
|
97
104
|
};
|
|
98
105
|
});
|
|
99
106
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -21,11 +21,23 @@ type Options = {
|
|
|
21
21
|
*/
|
|
22
22
|
hostname: string;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* The routes to include in the sitemap. Pass either strings or `SitemapEntry` objects
|
|
25
|
+
* for full control over "loc", "lastmod", "changefreq" and "priority".
|
|
25
26
|
*
|
|
26
27
|
* **Default: `['/']`**
|
|
28
|
+
*
|
|
29
|
+
* ---
|
|
30
|
+
*
|
|
31
|
+
* Example:
|
|
32
|
+
* ```ts
|
|
33
|
+
* routes: [
|
|
34
|
+
* '/',
|
|
35
|
+
* '/about',
|
|
36
|
+
* { loc: '/blog', lastmod: '2026-01-01', changefreq: 'weekly', priority: 0.8 },
|
|
37
|
+
* ]
|
|
38
|
+
* ```
|
|
27
39
|
*/
|
|
28
|
-
routes?: string[];
|
|
40
|
+
routes?: (string | SitemapEntry)[];
|
|
29
41
|
};
|
|
30
42
|
|
|
31
43
|
declare function sitemap(options: Options): Plugin;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,11 +21,23 @@ type Options = {
|
|
|
21
21
|
*/
|
|
22
22
|
hostname: string;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* The routes to include in the sitemap. Pass either strings or `SitemapEntry` objects
|
|
25
|
+
* for full control over "loc", "lastmod", "changefreq" and "priority".
|
|
25
26
|
*
|
|
26
27
|
* **Default: `['/']`**
|
|
28
|
+
*
|
|
29
|
+
* ---
|
|
30
|
+
*
|
|
31
|
+
* Example:
|
|
32
|
+
* ```ts
|
|
33
|
+
* routes: [
|
|
34
|
+
* '/',
|
|
35
|
+
* '/about',
|
|
36
|
+
* { loc: '/blog', lastmod: '2026-01-01', changefreq: 'weekly', priority: 0.8 },
|
|
37
|
+
* ]
|
|
38
|
+
* ```
|
|
27
39
|
*/
|
|
28
|
-
routes?: string[];
|
|
40
|
+
routes?: (string | SitemapEntry)[];
|
|
29
41
|
};
|
|
30
42
|
|
|
31
43
|
declare function sitemap(options: Options): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -55,9 +55,16 @@ var buildSitemapEntries = (options) => {
|
|
|
55
55
|
const host = options.hostname.replace(/\/$/, "");
|
|
56
56
|
const lastmod = (/* @__PURE__ */ new Date()).toISOString();
|
|
57
57
|
return options.routes.map((route) => {
|
|
58
|
+
if (typeof route === "string") {
|
|
59
|
+
return {
|
|
60
|
+
loc: `${host}/${route.replace(/^\/+/, "")}`,
|
|
61
|
+
lastmod
|
|
62
|
+
};
|
|
63
|
+
}
|
|
58
64
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
...route,
|
|
66
|
+
loc: `${host}/${route.loc.replace(/^\/+/, "")}`,
|
|
67
|
+
lastmod: route.lastmod ?? lastmod
|
|
61
68
|
};
|
|
62
69
|
});
|
|
63
70
|
};
|
package/package.json
CHANGED