I like to generate the sitemap.xml dynamically like list of cities added in storyblok based on the states, I have done the cities pages url dynamically by using createPage.
if (page.path.match(/^\/tn/)) {
page.matchPath = "/tn/*";
} else if (page.path.match(/^\/ap/)) {
page.matchPath = "/ap/*";
}
createPage(page);
But I am not able to generate in sitemap.xml
I am trying add these cities as constants for hack and generate sitemap.xml but thats also not happening, can anyone help me how to generate the sitemap.xml using constants in the gatsconfig.js
my config
resolve: `gatsby-plugin-sitemap`,
options: {
query: `
{
site {
siteMetadata {
siteUrl
}
}
}
`,
resolveSiteUrl: ({
site: {
siteMetadata: {
siteUrl
}
}
}) => siteUrl,
resolvePages: () => {
console.log("coming -------")
const cities = ['test', 'test2'].map(city => {
return {
path: `/tn/${city}`,
changefreq: 'weekly',
priority: 0.7,
}
})
console.log("cities", cities);
return [...cities]
},
serialize: ({
path,
changefreq,
priority
}) => {
return {
siteUrl: path,
changefreq,
priority,
}
},
}
}```
Here is the configuration that I use: