GithubHelp home page GithubHelp logo

hahlh / sanity-recipes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sanity-io/sanity-recipes

0.0 0.0 0.0 18.91 MB

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

Home Page: https://sanity.io/docs

License: MIT License

JavaScript 100.00%

sanity-recipes's Introduction

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.

sanity-recipes's People

Contributors

genox avatar j-v-a avatar karlguillotte avatar kmcaloon avatar kmelve avatar readeral avatar rexxars avatar runeb avatar skogsmaskin avatar tidiview avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.