mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.6 KiB
59 lines
1.6 KiB
1 year ago
|
# Sitemap Generation
|
||
|
|
||
|
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`:
|
||
|
|
||
|
```ts
|
||
7 months ago
|
export default {
|
||
1 year ago
|
sitemap: {
|
||
|
hostname: 'https://example.com'
|
||
|
}
|
||
7 months ago
|
}
|
||
1 year ago
|
```
|
||
|
|
||
|
To have `<lastmod>` tags in your `sitemap.xml`, you can enable the [`lastUpdated`](../reference/default-theme-last-updated) option.
|
||
|
|
||
|
## Options
|
||
|
|
||
|
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:
|
||
|
|
||
|
```ts
|
||
7 months ago
|
export default {
|
||
1 year ago
|
sitemap: {
|
||
|
hostname: 'https://example.com',
|
||
|
lastmodDateOnly: false
|
||
|
}
|
||
7 months ago
|
}
|
||
|
```
|
||
|
|
||
|
If you're using `base` in your config, you should append it to the `hostname` option:
|
||
|
|
||
|
```ts
|
||
|
export default {
|
||
|
base: '/my-site/',
|
||
|
sitemap: {
|
||
|
hostname: 'https://example.com/my-site/'
|
||
|
}
|
||
|
}
|
||
1 year ago
|
```
|
||
|
|
||
|
## `transformItems` Hook
|
||
|
|
||
|
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:
|
||
|
|
||
|
```ts
|
||
7 months ago
|
export default {
|
||
1 year ago
|
sitemap: {
|
||
|
hostname: 'https://example.com',
|
||
|
transformItems: (items) => {
|
||
|
// add new items or modify/filter existing items
|
||
|
items.push({
|
||
|
url: '/extra-page',
|
||
|
changefreq: 'monthly',
|
||
|
priority: 0.8
|
||
|
})
|
||
|
return items
|
||
|
}
|
||
|
}
|
||
7 months ago
|
}
|
||
1 year ago
|
```
|