gatsby-plugin-advanced-sitemap
gatsby-plugin-advanced-sitemap copied to clipboard
Allow for mapping to the same sitemap
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`
}
}```
That would be a very nice feature!!! PRs are very welcome 😃
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 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.