Gatsby-plugin-advanced-sitemap serializer

Is it possible to use a serializer in the mapping section? I (maybe not so brightly) have all my post types as one.

    {
  resolve: `gatsby-plugin-advanced-sitemap`,
  options: {
    // 1 query for each data type
    query: `
          {
            allSanityPost(filter: {slug: {current: {ne: "null"}}, postType: {title: {in: ["blog"]}}, publishedAt: {ne: "null"}}) {
              edges {
                node {
                  id
                  title
                  publishedAt
                  slug {
                    current
                  }
                  postType {
                    title
                  }
                  series {
                    slug {
                      current
                    }
                  }
                }
              }
            }
            allSanityPost(filter: {slug: {current: {ne: "null"}}, postType: {title: {in: ["lesson"]}}, publishedAt: {ne: "null"}}) {
              edges {
                node {
                  id
                  title
                  publishedAt
                  slug {
                    current
                  }
                  postType {
                    title
                  }
                  series {
                    slug {
                      current
                    }
                  }
                }
              }
            }
            allSanityPost(filter: {slug: {current: {ne: "null"}}, postType: {title: {in: ["course"]}}, publishedAt: {ne: "null"}}) {
              edges {
                node {
                  id
                  title
                  publishedAt
                  slug {
                    current
                  }
                  postType {
                    title
                  }
                  series {
                    slug {
                      current
                    }
                  }
                }
              }
            }
            allSanityAuthor {
              edges {
                node {
                  id
                  slug {
                    current
                  }
                  name
                  image {
                    asset {
                      url
                    }
                  }
                }
              }
            }
          }`,
    mapping: {
      // Each data type can be mapped to a predefined sitemap
      // Routes can be grouped in one of: posts, tags, authors, pages, or a custom name
      // The default sitemap - if none is passed - will be pages
      allGhostPost: {
        sitemap: `posts`,
      },
      allGhostTag: {
        sitemap: `tags`,
      },
      allGhostAuthor: {
        sitemap: `authors`,
      },
      allGhostPage: {
        sitemap: `pages`,
      },
    },
    exclude: [
      `/dev-404-page`,
      `/404`,
      `/404.html`,
      `/offline-plugin-app-shell-fallback`,
      `/my-excluded-page`,
      /(\/)?hash-\S*/, // you can also pass valid RegExp to exclude internal tags for example
    ],
    createLinkInHead: true, // optional: create a link in the `<head>` of your site
    addUncaughtPages: true, // optional: will fill up pages that are not caught by queries and mapping and list them under `sitemap-pages.xml`
  }

Hey @ajonp it’s currently not possible to merge source types together, like using allSanityPost for multiple queries. The other problem is that the plugin requires a slug field, which - according to your querieies - is nested. The plugin supports having the slug property nested within a fields property for Markdown and MDX types.

If you can find any other way to provide a slug identifier, which is used to link to the article, you could make your scenario work using e. g. this example:

{
  resolve: `gatsby-plugin-advanced-sitemap`,
  options: {
    // 1 query for each data type
    query: `
          {
           // name the source type for the query result
            blog:allSanityPost(filter: {slug: {current: {ne: "null"}}, postType: {title: {in: ["blog"]}}, publishedAt: {ne: "null"}}) {
              edges {
                node {
                  id
                  title
                  published_at: publishedAt // you need to rename the property
                  slug // this is a needed property
                }
              }
            }
            // name the source type for the query result
            lessons:allSanityPost(filter: {slug: {current: {ne: "null"}}, postType: {title: {in: ["lesson"]}}, publishedAt: {ne: "null"}}) {
              edges {
                node {
                  id
                  title
                  published_at: publishedAt // you need to rename the property
                  slug // this is a needed property
                }
              }
            }
            courses: allSanityPost(filter: {slug: {current: {ne: "null"}}, postType: {title: {in: ["course"]}}, publishedAt: {ne: "null"}}) {
              edges {
                node {
                  id
                  title
                  published_at: publishedAt // you need to rename the property
                  slug // this is a needed property
                }
              }
            }
            allSanityAuthor {
              edges {
                node {
                  id
                  slug
                  name
                }
              }
            }
          }`,
    mapping: {
      blog: {
        sitemap: `blog`,
      },
      lessons: {
        sitemap: `lessons`,
      },
      courses: {
        sitemap: `courses`,
      },
      allSanityAuthor: {
        sitemap: `authors`,
      },
    },
    exclude: [
      `/dev-404-page`,
      `/404`,
      `/404.html`,
      `/offline-plugin-app-shell-fallback`,
      `/my-excluded-page`,
      /(\/)?hash-\S*/, // you can also pass valid RegExp to exclude internal tags for example
    ],
    createLinkInHead: true, // optional: create a link in the `<head>` of your site
    addUncaughtPages: true, // optional: will fill up pages that are not caught by queries and mapping and list them under `sitemap-pages.xml`
}

This config will result in creating multiple sitemaps for each of your sections: blog, lessons, and courses.

Of course, this is just a suggestion. If this doesn’t work for you properly, then you can always fall back to use the default mapping, which queries allSitePage.

If you fancy submitting a PR with the option to pass a serializer, we’re happy to review and merge it!

Hope, that helped a bit!