Setting the file. One moment.
Skill 04 · Portable Text Serialization
Subchapter 4.4
rules/plain-text.mdMarkdown2 KBView on GitHub
Every @portabletext/* library exports a toPlainText() utility. Use it for meta descriptions, search indexing, summaries, and anywhere you need raw text without markup.
// From any framework library:
import {toPlainText} from '@portabletext/react'
// or: import {toPlainText} from '@portabletext/svelte'
// or: import {toPlainText} from '@portabletext/vue'
// or: import {toPlainText} from '@portabletext/to-html'
const plainText = toPlainText(portableTextBlocks)function getMetaDescription(body: PortableTextBlock[]): string {
const text = toPlainText(body)
return text.length > 160 ? text.slice(0, 157) + '...' : text
}// Index document content for search
const searchableText = toPlainText(document.body)import slugify from 'slugify'
const slug = slugify(toPlainText(blocks), {lower: true, strict: true})const text = toPlainText(blocks)
const wordCount = text.split(/\s+/).filter(Boolean).length
const charCount = text.lengthspan children in block type nodes\n\n)