gatsby-plugin-advanced-sitemap icon indicating copy to clipboard operation
gatsby-plugin-advanced-sitemap copied to clipboard

Allow for mapping to the same sitemap

Open kramerkm opened this issue 5 years ago • 3 comments

I'm currently working on a website and need to create separate sitemaps for each product type. In order to to do this, I need to combine multiple queries into 1 sitemap file. Is there a way to map separate queries to the same sitemap and just have it continue adding rather than replacing?

query: `
{
    allSocks { ... }
    allShoes { ... }
    allSocksDetails { ... }
}`,
mapping: {
    allSocks: {
        sitemap: `socks`
    },
    allShoes: {
        sitemap: `shoes`
    },
    allSocksDetails: {
        sitemap: `socks`
    }
}```

kramerkm avatar Feb 05 '20 23:02 kramerkm

That would be a very nice feature!!! PRs are very welcome 😃

aileen avatar Feb 11 '20 13:02 aileen

I have the opposite problem - I have one query and want to be able to split it into multiple sitemaps. Can this be achieved?

Example:

query: `
  allSitePage { ... }
`,
mapping: {
  allSitePage: {
    sitemap: `products`, // by filtering the query result with some logic
    sitemap: `category`, // by filtering the query result with some logic
    sitemap: ...
  }
}

Also let me know if this belongs to a new Issues entry!

fmaiabatista avatar May 06 '21 14:05 fmaiabatista

@fmaiabatista you could theoritically just use aliases in your gql to bypass this I think.

query: `{
  products: allSitePage { ... }
  category: allSitePage { ... }
}`

I agree with the OP. Being able to combine queries into one would be super useful. Only way around this I can think of would be to create a new set of nodes using sourceNodes with the combined queries then querying those new nodes that way. @aileen would that work?

This could also be solved by allowing a top level serializer rather than on each individual query, so on the top level query, which you would then return the objects for creating the sitemaps.

It would go something like:

query: `{ 
  categories: {...}
  products: {...}
}`,
serializer: (({ products, categories }) => {
  const productMap = products.map(...)
  const categoriesMap = categories.map(...)
  
  return {
     ["name_of_sitemap"]: productMap,
     ["categories_sitemap"]: categoriesMap
    }
}) 

Just as an example.

tbaustin avatar Jun 21 '21 19:06 tbaustin