Skip to content

Commit 99c0cec

Browse files
committed
docs: add notes for sitemap + base
closes #3863
1 parent fa2f38a commit 99c0cec

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

docs/guide/sitemap-generation.md

+17-12
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
VitePress comes with out-of-the-box support for generating a `sitemap.xml` file for your site. To enable it, add the following to your `.vitepress/config.js`:
44

55
```ts
6-
import { defineConfig } from 'vitepress'
7-
8-
export default defineConfig({
6+
export default {
97
sitemap: {
108
hostname: 'https://example.com'
119
}
12-
})
10+
}
1311
```
1412

1513
To have `<lastmod>` tags in your `sitemap.xml`, you can enable the [`lastUpdated`](../reference/default-theme-last-updated) option.
@@ -19,24 +17,31 @@ To have `<lastmod>` tags in your `sitemap.xml`, you can enable the [`lastUpdated
1917
Sitemap support is powered by the [`sitemap`](https://www.npmjs.com/package/sitemap) module. You can pass any options supported by it to the `sitemap` option in your config file. These will be passed directly to the `SitemapStream` constructor. Refer to the [`sitemap` documentation](https://www.npmjs.com/package/sitemap#options-you-can-pass) for more details. Example:
2018

2119
```ts
22-
import { defineConfig } from 'vitepress'
23-
24-
export default defineConfig({
20+
export default {
2521
sitemap: {
2622
hostname: 'https://example.com',
2723
lastmodDateOnly: false
2824
}
29-
})
25+
}
26+
```
27+
28+
If you're using `base` in your config, you should append it to the `hostname` option:
29+
30+
```ts
31+
export default {
32+
base: '/my-site/',
33+
sitemap: {
34+
hostname: 'https://example.com/my-site/'
35+
}
36+
}
3037
```
3138

3239
## `transformItems` Hook
3340

3441
You can use the `sitemap.transformItems` hook to modify the sitemap items before they are written to the `sitemap.xml` file. This hook is called with an array of sitemap items and expects an array of sitemap items to be returned. Example:
3542

3643
```ts
37-
import { defineConfig } from 'vitepress'
38-
39-
export default defineConfig({
44+
export default {
4045
sitemap: {
4146
hostname: 'https://example.com',
4247
transformItems: (items) => {
@@ -49,5 +54,5 @@ export default defineConfig({
4954
return items
5055
}
5156
}
52-
})
57+
}
5358
```

0 commit comments

Comments
 (0)