🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Help needed with Next.js and Sanity integration, getting 404 error and build error

10 replies
Last updated: Feb 2, 2023
We're looking into the possibility of trying Sanity at my company. We have content in a few countries, not just localized but different content. There would be 5 + dev content set(s). We really like the usage based pricing model of Sanity, but the dataset limits are a bit concerning. Is it possible to have more?
Feb 2, 2023, 3:36 PM
Would consider keeping it all in a common dataset as there usually are some data that can be shared.
Feb 2, 2023, 4:34 PM
We’ve created multiple sites like this either using the i18n plugin or just by having every document reference a “site”/“language” document.
Feb 2, 2023, 4:34 PM
What would be the authoring flow then? I cannot expect the people editing this to put the country in every document they make. Especially not with references. Would it be possible to hide, and then filter all documents everywhere based on some selector in the navbar for example?
Feb 2, 2023, 4:52 PM
We have entirely different teams editing these.
Feb 2, 2023, 4:53 PM
Yep! You can create custom desk structure to only show each country and only show specific countries to each user.
The “Site” field is hidden for users and auto populated via initial value templates
🙂
You can then make sure every reference field uses a “filter references” function like this one:


export const filterInternalLinkBySite = ({ document }) => {
  if (!document?.sites) {
    return {
      filter: "",
      params: "",
    }
  }

  const siteIds = document?.sites.map((site) => site._ref)

  return {
    filter: "(count((sites[]._ref)[@ in $siteIds]) > 0) && _id != $id",
    params: {
      siteIds: siteIds,
      id: document?._id,
    },
  }
}
Feb 2, 2023, 6:13 PM
Hmm. Then when we I query I'd need to include a filter on everything as well right?
Feb 2, 2023, 6:14 PM
Yup, using Next.js as a frontend we have this setup using i18n locales:

*[_type == "page" && $locale in sites[]->locale]

Note both these examples have the site field as “sites” since some content might be usable on different sites, such as swedish content in swedish part of finnish page
😉
Feb 2, 2023, 6:19 PM
We don't hace anything shared, intentionally.
Feb 2, 2023, 6:23 PM
But yeah that might work actually.
Feb 2, 2023, 6:23 PM
The great thing is that with this setup you can mix in content that is better to have field level translations or no translations such as Person or Product.
In addition you share the same media library which is usually nice
Feb 2, 2023, 6:23 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?