Reputation: 655
I'm trying to generate sitemaps via gatsby-plugin-sitemap
and it works with all the default options and generate the sitemaps however if I try to modify the sitemap generation in anyway it doesn't seems to have any affect whatsoever e.g. I want to remove the changefreq and priority, it doesn't work and when I try to filter the pages it doesn't work either.
This is how my config looks like:
{
resolve: `gatsby-plugin-sitemap`,
options: {
output: `/testsitemap.xml`,
},
query: `{
site {
siteMetadata {
siteUrl
}
}
allJsonJson {
edges {
node {
noindex
hrefs {
href
}
}
}
}`,
serialize: ({ site, allJsonJson }) => {
return allJsonJson.edges
.filter(({node}) => (
node.noindex !== true
))
.map(({node}) => {
node.hrefs.map(({href}) => {
return {
url: `${site.siteMetadata.siteUrl}${href}`
};
})
})
},
}
This is driving me nuts as I'm trying to make it work for quite sometime now and can't proceed at all. Any ideas?
GraphQL Editor:
"allJsonJson": {
"edges": [
{
"node": {
"noindex": null,
"hrefs": [
{
"href": "/about/"
},
{
"href": "/aa/test.../"
}
]
}
}
]
}
Upvotes: 1
Views: 1515
Reputation: 1305
I nearly moved to Next.js trying to figure this out...
{
resolve: 'gatsby-plugin-sitemap',
options: {
query: `
{
allSitePage {
nodes {
path
pageContext
}
}
}
`,
resolveSiteUrl: () => 'https://yourwebsite.com/',
resolvePages: ({ allSitePage: { nodes: allPages } }) => {
return allPages.filter((page) => {
// Don't want to add private routes to the sitemap
if (page.path.includes('/dashboard')) {
return false;
}
return true;
});
},
},
},
Upvotes: 1