Hi, I really need some explanation about the proper usage of serializer inside the Gatsby plugin for advanced sitemaps. I am using Contentful as my CMS, gatsby 2.24.80, node 12.18.3, advanced sitemap is 1.6.0. My current setup in gatsby-config.js is looking like this:
{
resolve: `gatsby-plugin-advanced-sitemap`,
options: {
query: `
{
allBlogPostDe: allContentfulBlogPost(filter: {node_locale: {eq: "de-DE"}}) {
edges {
node {
id
slug
updated_at: updatedAt
}
}
}
}
`,
mapping: {
allBlogPostDe: {
sitemap: `pages-de`,
serializer: edges => {
return edges.map(({ node }) => {
const urlPath = node.slug.split("")[0] === "/" ? `de${node.slug}` : `de/${node.slug}`
return {
url: `${site_url}${urlPath}`,
lastmodISO: node.updated_at,
}
})
},
},
},
exclude: [
`/dev-404-page`,
`/404`,
`/404.html`,
`/offline-plugin-app-shell-fallback`,
],
createLinkInHead: true,
addUncaughtPages: true, // add pages that are not caught by queries and mapping under `sitemap-pages.xml`
},
},
My question is how to use this Serializer properly because with this setup I get the following error:
Cannot read property ‘__typename’ of undefined
When I remove the serializer I get the sitemap generated on the /sitemap-pages-de.xml without errors, but because I can’t use the prefix added for locale, it will look the same as urls for english version (those doesn’t have any prefix). So, what am I missing here in the code I really don’t know to make this custom with url prefix in sitemap. Example: http://localhost:9001/de/my-blog-post
Also format of updatedAt field is in ISO format that is why I used the lastmodISO. That is also another question: Is this supported by your plugin?
Thanks a lot in advance because I am really hitting the wall now. In your readme file there is no mention about the example of serializer and its custom logic. There is example for non-advanced plugin but that one doesn’t support multiple sitemaps which I need.
Thanks , Ivan