Join us live Sept. 27 – How Sanity and Vercel powered Morning Brew's transformation –>

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: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.