Roboto Studio
The best editorial experiences on the web
Quickly and easily validate your slug without having to work out the regex syntax
This recipe is for an older version of Sanity Studio (v2), which is deprecated.
Learn how to migrate to the new Studio v3 →export default {
title: "Basic Usage",
name: "basicUsage",
type: "document",
fields: [
{
name: "slug",
title: "Slug",
type: "slug",
options: {
//Change to schema title to automatically populate
source: "title",
slugify: (input) =>
input
.toLowerCase()
//Remove spaces
.replace(/\s+/g, "-")
//Remove special characters
.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, ""),
validation: (Rule) => Rule.required(),
},
},
],
};
import SlugInput from "sanity-plugin-better-slug";
export default {
title: "Sanity Plugin Better Slug Usage",
name: "betterSlugUsage",
type: "document",
fields: [
{
name: "slug",
title: "Slug",
type: "slug",
inputComponent: SlugInput, //Reference the SlugInput
options: {
//Change to schema title to automatically populate
source: "name",
//Use your URL
basePath: "https://example.org",
maxLength: 30,
slugify: (input) =>
input.toLowerCase()
.replace(/\s+/g, "-").slice(0, 200),
//Remove special characters
.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, ""),
validation: (Rule) => Rule.required(),
},
},
],
};
A very bare bones way of ensuring your slugs are without spaces and special characters. It's also a very UX friendly way of handling this from a client side.
The best editorial experiences on the web
Create Next.js redirects, directly inside of your Sanity Studio with validation
Go to Next.js Redirect schema with validationThinking about getting started with AI? Well we're just going to share our latest and greatest prompt so you don't have to do the hard work
Go to Cursor PromptOn the fly form generation with Sanity & Formspark
Go to Sanity & Formspark Form GeneratorIf you're looking to mockup portable text in Storybook without a Sanity backend, this is the schema you're looking for
Go to Portable Text Mock ContentContent operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store