GraphQL: Better filtering for `seoTags.noIndex` to exclude pages from sitemap (edited title)

I want to generate a sitemap with dato in using nextjs. I saw @m.finamor suggesting next sitemap, a package I love. We used to have a custom field for blocking the search index of a page, a simple boolean which did the job. We used this boolean to get all pages where this boolean was true only returning a couple of pages in the response (see query below).

    first: 100
    orderBy: _createdAt_DESC
    filter: { blockSearchIndexing: { eq: "true" } }
  ) {
    _allSlugLocales {

Then excluding it in the config:

  exclude: async () => {
    const data = await fetchGraphQLData();

    const extractedSlugs = extractAllSlugLocales(data);

    return extractedSlugs;

Now we are using Dato their latest “no index” feature:

I can’t find a performant way to exclude these pages from the sitemap.

Any ideas? :smiley:

Hmm… this feels like an oversight on our part :frowning: We do have a filter for seoTags, but the only operator is a boolean exists… either it has SEO tags (of any sort) or not, which isn’t useful for differentiating between the noIndex entries and the rest.

Let me check with the devs on this!

In the meantime, do you have a lot of overall pages? Is it doable to just fetch all of them and filter on the clientside, e.g. noIndexPosts = allPosts.filter(post => post.seoTags?.noIndex === true)? Presumably you have to retrieve all the posts to build your sitemap anyway, so in that same file you can also loop through that array and exclude the ones set to noIndex.

You can also add another field, for now, like “Exclude from sitemap?” and filter on that instead. You can also use a plugin like Computed Fields - Plugins — DatoCMS to derive it from the SEO field… but you really shouldn’t have to jump through hoops like that. I’ll let you know what the devs say as soon as we hear back.

Hi @thomas.habets,

I checked with the devs, and sorry, this isn’t a feature we currently support :frowning: I’ll convert this into a feature request for you.

In the meantime, I hope the clientside filter could work?

@roger thank you for the reply. We’ll get the clientside filter running. Looking forward to this feature! Would be a great addition to Dato. Haven’t seen any headless CMS providing a “clean” solution to this issue.