Sitemap from `gatsby-plugin-advanced-sitemap` excludes `/`

I’m very happy with the sitemap produced by Ghost’s gatsby-plugin-advanced-sitemap, except for the fact that it excludes the home page (/ route) from the sitemap (all other routes are properly included). Is this by design? If so, what is the recommended way to configure the plugin to include the / route in the generated sitemap?

I’m using the default gatsby-config settings described in the documentation:

siteMetadata: {
    ...
    siteUrl: 'https://the-name-of-my.app'
  },
plugins: [
    ...
    'gatsby-plugin-advanced-sitemap',
    ....
]

Hey there @NWRichmond :wave:. That seems odd, you’ll notice if you click on sitemap-pages in this example sitemap that the home page is listed as a an actual page: https://gatsby.ghost.org/sitemap.xml

Do you have any specific settings or a particular setup to your project?

Thanks for getting back so quickly, @DavidDarnes.

Project Setup

Do you have any specific settings or a particular setup to your project?

I have a very straight-forward project setup with "gatsby": "^2.15.14" and "gatsby-plugin-advanced-sitemap": "^1.4.4". Just a handful of plugins, with 5 routes from the pages directory that I want in the sitemap. Included in these 5 desired sitemap entries is the the / route for my index.js page.

Things I’ve Tried

I was using this plugin without any config at first, but after noticing that:

  • there are routes in the sitemap that I don’t want to include, and
  • the / route is excluded from sitemap-pages.xml

I tried the following config after testing the allSitePage query in GraphiQL:

...
{
  resolve: `gatsby-plugin-advanced-sitemap`,
  options: {
    query: `
    {
      allSitePage {
        edges {
          node {
            path
            slug: path
            url: path
          }
        }
      }
    }
    `,
    mapping: {
      allSitePage: {
        sitemap: `pages`,
      },
    },
    exclude: [
      `/dev-404-page`,
      `/404`,
      `/404.html`,
      `/account`,
      `/assets`,
      `/loading`,
      `/offline-plugin-app-shell-fallback`,
    ],
    createLinkInHead: true, // optional: create a link in the `<head>` of your site
    addUncaughtPages: true, // optional: will fill up pages that are not caught by queries and mapping and list them under `sitemap-pages.xml`
  },
},
...

The resulting sitemap-pages.xml does include the / route, but it removes all of the other routes aside from /pricing, which is the alphabetically-last route.

I don’t know how the plugin works, but to me it seems like maybe an array of the routes returned by allSitePage is being iterated over, returning a single value that keeps being overwritten.

The Goal

Since I want to exclude some routes from my sitemap, getting the plugin working with the config would be my top priority (in my case, working = a sitemap with /, /pricing, and the 3 missing routes). But the problem remains that the / route for pages/index.js isn’t included without a special config. I can’t share the repository for this project (monorepo w/backend IP), but I’m happy to provide any information about the gatsby setup I’m using.

Also, I tried switching

{
addUncaughtPages: true
}

to

{
addUncaughtPages: false
}

and the only result was switching the order of the two pages in the sitemap so that the / route is first:

This is odd. I wonder if the bug persists if you remove the excludes? :thinking:

Hey @NWRichmond

You are right! This is a bug and I was able to reproduce it. I opened an issue for it here :point_right:t3:https://github.com/TryGhost/gatsby-plugin-advanced-sitemap/issues/9

The order that changed in your sitemap between / and /pricing shouldn’t have anything to do with it. The order in sitemaps is determined by the “Last Modified” timestamp, which changed between your first and second screenshot.

1 Like

Thanks @Aileen for confirming the issue and testing with Gatsby Starter Ghost!

@DavidDarnes I tried removing the excludes array, but this doesn’t seem to change anything.

So to summarize, no matter if the excludes option is provided or not, only / and the alphabetically-last result of the allSitePage query are included in the sitemap when I set the query option, as described in my earlier post.

I’ve got a lot on my plate at the moment but I will try to get a public repo with a minimum reproducible example as soon as possible. If I find more time, I’ll dive in to the plugin repo and see if I can track down bug #9.

2 Likes