TryGhost / gatsby-plugin-advanced-sitemap

Advanced XML Sitemaps for Gatsby.js
MIT License
150 stars 0 forks source link

Exclude excludes more than exact matches #114

Open YoungiiJC opened 3 years ago

YoungiiJC commented 3 years ago

Hey there. It seems the exclude method is not working correctly. When I exclude /team, pages such as /submit-your-team or /request-a-team are excluded as well.

Line 186 of gatsby-node.js is:

return slug.indexOf(excludedRoute) >= 0

/* logged output
{
  excludedRoute: 'team/',
  slug: 'suggest-a-team/',
  match: true,
}
*/

This might be by design, so correct me if I'm wrong 😄 But looks like slug and excludedRoute are transposed. indexOf should return a strict equality match. We get a strict match if we do :

return excludedRoute.indexOf(slug) >= 0

/* logged output
{
  excludedRoute: 'team/',
  slug: 'suggest-a-team/',
  match: false,
}
*/

Note: this fix breaks the default exclusion of /dev-404-page/`, `/404/`, `/404.html.

In case this helps, I'm on "gatsby": "^2.12.1" and here's my config:

    {
      resolve: `gatsby-plugin-advanced-sitemap`,
      options: {
        exclude: [`/team`, `/team/`, `/dev-404-page/`, `/404/`, `/404.html`],
        query: `{
          allPublishedTeams {
            edges {
              node {
                slug
                image
              }
            }
          }
        }`,
        mapping: {
          allPublishedTeams: {
            sitemap: `teams`,
          },
        },
        addUncaughtPages: true,
      },
    },

I'm happy to open a PR for this change. Let me know :)

francesco-serialparts commented 3 years ago

I have a similar problem about the not exact match between URL. I have several sitemaps with URL queried from different queries, one of that is from an custom post in an headless WP source allWordpressWpGuide. When I use the plugin, some posts of this query go between the UncaughtPages and are been replaced from other posts (from blog or custom post) with similar URL.