Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion src/content/docs/en/guides/integrations-guide/sitemap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,59 @@ export default defineConfig({
});
```

### `i18n`
### `chunks`

<p>

**Type:** `Record<string, (item: SitemapItem) => SitemapItem | undefined>`
<Since v="3.7.0" pkg="@astrojs/sitemap" />
</p>

A map of functions that allows you to split your sitemap into multiple files based on custom logic. Each key in the object becomes the name of a separate sitemap file, and its corresponding function determines which URLs will be included in that chunk. This can be useful for instance if a specific section of your website changes very often and you'd like to specify a different change frequency for its entries.

Each chunk function receives a `SitemapItem` and for each item returns either:
* the modified `SitemapItem`, if the URL should be included in this chunk
* `undefined`, if the URL should not be included in this chunk

The example below shows how to split URLs into different sitemap files based on their path:

```js title="astro.config.mjs" ins={8-26}
Comment thread
Princesseuh marked this conversation as resolved.
Outdated
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';

export default defineConfig({
site: 'https://example.com',
integrations: [
sitemap({
chunks: {
'blog': (item) => {
if (/blog/.test(item.url)) {
item.changefreq = 'weekly';
item.lastmod = new Date();
item.priority = 0.9;
return item;
}
},
'glossary': (item) => {
if (/glossary/.test(item.url)) {
item.changefreq = 'monthly';
item.lastmod = new Date();
item.priority = 0.7;
return item;
}
}
},
}),
],
});
```

This configuration will generate the following files:

- `sitemap-blog-0.xml`
- `sitemap-glossary-0.xml`

URLs that don't match any chunk will be placed in a default `sitemap-pages-0.xml` file.

<p>

Expand Down