Is there any way to prefix a slug, ie category page for mens would be /category/mens?

2 replies
Last updated: Sep 17, 2020
Is there any way to prefix a slug, ie category page for mens would be /category/mens - it most likely me being stupid so points in the right direction would be helpful aswell
Sep 17, 2020, 8:54 PM
You could set up a custom source function to achieve this. For example:
{
  title: 'Slug',
  name: 'slug',
  type: 'slug',
  options: {
    source: doc => `/category/${doc.category}`
  }
}
Sep 17, 2020, 9:20 PM
That’s probably because the default
slugify
function replaces slashes. Something like this should get you closer 🙂
{
  title: 'Slug',
  name: 'slug',
  type: 'slug',
  options: {
    source: doc => `/category/${doc.category}`,
    slugify: input => input
      .toLowerCase()
      .slice(0, 200)
  }
}
Sep 17, 2020, 9:31 PM

Sanity.io – build remarkable experiences at scale

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