Recipes

Sanity Functions Recipes

Automate your content workflows with functions that trigger on document events. From AI-powered automatic tagging and content enrichment to translation and optimization, these pre-built functions save time and improve content quality across your Sanity projects.

Format code blocks with Prettier

Official(made by Sanity team)

Automatically format code blocks using Prettier to enforce consistency across all documents.

Simeon Griggs
Go to Format code blocks with Prettier

Automatically tag blog posts

Featured contribution
Official(made by Sanity team)

AI-powered automatic tagging for Sanity blog posts that analyzes content to generate 3 relevant tags, maintaining consistency by reusing existing tags from your content library.

Go to Automatically tag blog posts

First Published Timestamp Function

Featured contribution
Official(made by Sanity team)

Automatically track when content was first published with a timestamp that sets once and never overwrites, providing reliable publication history for analytics and editorial workflows.

Knut Melvær
Go to First Published Timestamp Function

Sentiment Analysis

Automatically analyze and categorize the emotional tone of user comments

Pieter Brinkman
Go to Sentiment Analysis

Auto Summary Function

Official(made by Sanity team)

AI-Powered Content Summary from Long Form Content

Kevin Green
Go to Auto Summary Function

Telegram alerts for new comments

Official(made by Sanity team)

Get instant Telegram notifications when new comments are posted, with direct links to your Sanity Studio.

Simeon Griggs
Go to Telegram alerts for new comments

Post to Bluesky

Official(made by Sanity team)

Inform your the Bluesky crowd when you publish a post

Go to Post to Bluesky

Post to Mastodon

Official(made by Sanity team)

Spread the word on Mastodon when publishing a blog post

Go to Post to Mastodon

Latest recipes

Matching the end of a string in GROQ

GROQ doesn't yet include a function to match the end of a string, but we can simulate it by splitting our string on our term.

Geoff Ball
Go to Matching the end of a string in GROQ

Unlimited nesting

This snippet is useful if you want a desk structure that allows columns with a parent page and children pages underneath it. As deep as you would like.

René Hasert
Go to Unlimited nesting

groqd implementation with portable text custom marks

If you're working on integrating portable text with custom markDefs using groqd, the following code snippet could be very useful. It might save you a considerable amount of research time.

Oybek Khalikovic
Go to groqd implementation with portable text custom marks

Portable Text Mock Content

If 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 Content