Espen Hovlandsdal
Open-sourceror @ Sanity.io
Espen is located at Berkeley, CA
A small help function to convert Portable Text blocks to plain text
const defaults = {nonTextBehavior: 'remove'}
module.exports = function blocksToText(blocks, opts = {}) {
const options = Object.assign({}, defaults, opts)
return blocks
.map(block => {
if (block._type !== 'block' || !block.children) {
return options.nonTextBehavior === 'remove' ? '' : `[${block._type} block]`
}
return block.children.map(child => child.text).join('')
})
.join('\n\n')
}
This function traverses the top-level blocks in a Portable Text array and joins the text property in its children. It also includes a pattern to deal with non-text blocks in a specific manner.
Open-sourceror @ Sanity.io
🚫 MyFile / ✅ MyFile.pdf
Go to Add extensions to asset original filenamesA script to validate that your schema is free of errors and warnings
Go to Validate schema scriptDrop this into your Studio to let editors know when there's a more recent version of your Studio available, making sure they have the latest fields and validations.
Go to Auto-reload Studio when changes are deployedScript to find and delete unused assets in a dataset
Go to Delete unused assets