Sitemap
Guides

Multi Sitemaps

Generate multiple sitemaps for different sections of your site.

The module will generate a single /sitemap.xml file by default, for most websites this is perfect.

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 sitemaps option, which has two options:

  • object - Enables manual chunking. Recommended when you have clear content types (pages, posts, etc) or less than 1000 URLs
  • true - 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/**',
        ]
      },
    },
  },
})

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 option.

  • defaults - Sitemap default values such as lastmod, changefreq, or priority
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 sources
  • include - Array of glob patterns to include in the sitemap
  • exclude - Array of glob patterns to exclude from the sitemap
nuxt.config.ts
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.sources and need to filter URLs further, then you can use the _sitemap key.

  • _sitemap - The name of the sitemap that the URL should be included in
export default defineNuxtConfig({
  sitemap: {
    sources: [
      '/api/sitemap-urls'
    ],
    sitemaps: {
      pages: {
        includeAppSources: true,
        exclude: ['/**']
        // ...
      },
    },
  },
})

Managing Sources

If you need to fetch the URLs from an endpoint for a sitemap, then you will need to use either the urls or sources option.

  • urls - Array of static URLs to include in the sitemap. You should avoid using this option if you have a lot of URLs
  • sources - 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 index which allows you to easily extend the index sitemap. This can be useful for adding an external sitemap.

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 0-sitemap.xml, 1-sitemap.xml naming convention.

It will be chunked on the defaultSitemapsChunkSize option, which defaults to 1000 URLs per sitemap.

You should avoid using this if you have less than 1000 URLs.

export default defineNuxtConfig({
  sitemap: {
    // automatically chunk into multiple sitemaps
    sitemaps: true,
  },
})