Multi Sitemaps
Introduction
The module will generate a single
However, for larger sites that start having over thousands of URLs, introducing multiple sitemaps can help you to debug your sitemap easier and also help search engines to crawl your site more efficiently.
Enabling Multiple Sitemaps
If you want to generate multiple sitemaps, you can use the
object - Enables manual chunking. Recommended when you have clear content types (pages, posts, etc) or less than 1000 URLstrue - Enables automatic chunking. Recommended when you have a more than 1000 URLs and don't have clear content types.
export default defineNuxtConfig({
sitemap: {
// manually chunk into multiple sitemaps
sitemaps: {
posts: {
include: [
'/blog/**',
],
// example: give blog posts slightly higher priority (this is optional)
defaults: { priority: 0.7 },
},
pages: {
exclude: [
'/blog/**',
]
},
},
},
})
export default defineNuxtConfig({
sitemap: {
sitemaps: true,
// modify the chunk size if you need
defaultSitemapsChunkSize: 2000 // default 1000
},
})
Manual Chunking
When manually chunking your sitemaps, there are multiple ways of handling it depending on what you need.
In either case, if you'd like to provide defaults for URLs within the sitemap you can use the
defaults - Sitemap default values such aslastmod ,changefreq , orpriority
export default defineNuxtConfig({
sitemap: {
sitemaps: {
posts: {
// posts low priority
defaults: { priority: 0.7 },
},
},
},
})
Extending App Sources
When your single sitemap contains all the correct URLs and you just want to split them up into separate sitemaps, you can extend the app sources and filter the URLs.
includeAppSources - Uses app sourcesincludeGlobalSources - Uses global sourcesinclude - Array of glob patterns to include in the sitemapexclude - Array of glob patterns to exclude from the sitemap
export default defineNuxtConfig({
sitemap: {
sitemaps: {
pages: {
// extend the nuxt:pages app source
includeAppSources: true,
// filter the URLs to only include pages
exclude: ['/blog/**'],
},
posts: {
// extend the nuxt:pages app source
includeAppSources: true,
// filter the URLs to only include pages
include: ['/blog/**'],
},
},
},
})
If you're using a global
_sitemap - The name of the sitemap that the URL should be included in
export default defineNuxtConfig({
sitemap: {
sources: [
'/api/sitemap-urls'
],
sitemaps: {
pages: {
includeGlobalSources: true,
includeAppSources: true,
exclude: ['/**']
// ...
},
},
},
})
export default defineSitemapEventHandler(() => {
return [
{
loc: '/about-us',
// will end up in the pages sitemap
_sitemap: 'pages',
}
]
})
Managing Sources
If you need to fetch the URLs from an endpoint for a sitemap, then you will need to use either the
urls - Array of static URLs to include in the sitemap. You should avoid using this option if you have a lot of URLssources - Custom endpoint to fetch dynamic URLs from.
export default defineNuxtConfig({
sitemap: {
sitemaps: {
posts: {
urls() {
// resolved when the sitemap is shown
return ['/foo', '/bar']
},
sources: [
'/api/sitemap-urls'
]
},
},
},
})
Linking External Sitemaps
This mode also provides a special key called
export default defineNuxtConfig({
sitemaps: {
// generated sitemaps
posts: {
// ...
},
pages: {
// ...
},
// extending the index sitemap with an external sitemap
index: [
{ sitemap: 'https://www.google.com/sitemap-pages.xml' }
]
}
})
Automatic Chunking
This will automatically chunk your sitemap into multiple-sitemaps, using the
It will be chunked on the
You should avoid using this if you have less than 1000 URLs.
export default defineNuxtConfig({
sitemap: {
// automatically chunk into multiple sitemaps
sitemaps: true,
},
})