Skip to content

A collection of recipies / snippets / frequently asked questions about Sanity.io

License

Notifications You must be signed in to change notification settings

vrease/sanity-recipes

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sanity-recipes

Just a collection of recipies / snippets / frequently asked questions about Sanity.

Note that these things are just meant as inspiration and is usually not documented. You'll usually have to copy + paste the code and possibly adjust it slightly to fit your use case. Some might be published as NPM modules at some point if it makes sense.

Table of Contents


Portable Text Content

Portable Text as plain text

Sometimes you just want to skim over a whole bunch of Portable Text as text. This function does this, with some basic options for handling non-text nodes.

Convert quotation marks in Portable Text

Someone wanted to convert "whatever" to «whatever» when rendering. convertQuotationMarks() to the rescue!

Content Migrations

Delete unused assets

When uploading images and files, sometimes you are left with assets that are no longer in use by any documents. In these cases, you may want to purge the unused assets to free up some space and clear the clutter. This will probably be a core part of the Sanity toolkit at some point, but until then, this script should help you!

Uploading assets concurrently

A script which demonstrates how to upload multiple assets (images in this case) concurrently. Edit projectId, dataset and token. Also, edit the concurrency constant to change how many uploads run in parallel. To run the script: node snippets/uploadImagesConcurrently.js

Rename fields

Sometimes you want to change the name of a field. This function can be run with sanity exec renameField.js --with-user-credentials and do a migration even while users are working.

Components

Filter-aware Custom Input Component

The Sanity documentation contains several examples on how to create a Custom Input Component, but what if you want one which is also aware of language filter options? This component provides a good point of departure for making your own.

Conditional fields Custom Input Component

This custom input component shows an example of how to render a field conditionally of a field’s value in your document.

License

All code is MIT-licensed. See LICENSE.

About

A collection of recipies / snippets / frequently asked questions about Sanity.io

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%