Skip to content

Commit

Permalink
docs: add notes for sitemap + base
Browse files Browse the repository at this point in the history
closes #3863
  • Loading branch information
brc-dd committed May 4, 2024
1 parent fa2f38a commit 99c0cec
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions docs/guide/sitemap-generation.md
Expand Up @@ -3,13 +3,11 @@
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
import { defineConfig } from 'vitepress'

export default defineConfig({
export default {
sitemap: {
hostname: 'https://example.com'
}
})
}
```

To have `<lastmod>` tags in your `sitemap.xml`, you can enable the [`lastUpdated`](../reference/default-theme-last-updated) option.
Expand All @@ -19,24 +17,31 @@ To have `<lastmod>` tags in your `sitemap.xml`, you can enable the [`lastUpdated
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
import { defineConfig } from 'vitepress'

export default defineConfig({
export default {
sitemap: {
hostname: 'https://example.com',
lastmodDateOnly: false
}
})
}
```

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/'
}
}
```

## `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
import { defineConfig } from 'vitepress'

export default defineConfig({
export default {
sitemap: {
hostname: 'https://example.com',
transformItems: (items) => {
Expand All @@ -49,5 +54,5 @@ export default defineConfig({
return items
}
}
})
}
```

0 comments on commit 99c0cec

Please sign in to comment.