Skip to main content

gatsby-plugin-sitemap

Create a sitemap for your Gatsby site.

Install

npm install --save gatsby-plugin-sitemap

How to Use

// In your gatsby-config.js
siteMetadata: {
  siteUrl: `https://www.example.com`,
},
plugins: [`gatsby-plugin-sitemap`]

Above is the minimal configuration required to have it work. By default, the generated sitemap will include all of your site’s pages, except the ones you exclude.

Options

The defaultOptions here can be overridden.

We ALWAYS exclude the following pages: /dev-404-page/,/404 &/offline-plugin-app-shell-fallback/, this cannot be changed.

Example:

// In your gatsby-config.js
siteMetadata: {
  siteUrl: `https://www.example.com`,
},
plugins: [
  {
    resolve: `gatsby-plugin-sitemap`,
    options: {
      output: `/some-other-sitemap.xml`,
      // Exclude specific pages or groups of pages using glob parameters
      // See: https://github.com/isaacs/minimatch
      // The example below will exclude the single `path/to/page` and all routes beginning with `category`
      exclude: ["/category/*", `/path/to/page`],
      query: `
        {
          site {
            siteMetadata {
              siteUrl
            }
          }

          allSitePage {
            edges {
              node {
                path
              }
            }
          }
      }`
    }
  }
]

NOTE: This plugin only generates output when run in production mode! To test your sitemap, run: gatsby build && gatsby serve


Was this helpful? edit this page on GitHub