import type { MinimalElement, MinimalNode } from '@nuxt/content' type TypedRecord = Record type PlainText = { meta: TypedRecord text: string } const extractText = (element ?: MinimalNode) : string => { if (!element) return '' if (typeof element === 'string') return element const [,, ...nodes] = element return nodes?.map((el : MinimalNode) => typeof el === 'string' ? el : extractText(el)).join(' ') ?? '' } export const generatePlainText = (body ?: MinimalNode[]) : PlainText[] => { if (!body) return [] return body.map>(part => { const [, meta] = part as MinimalElement return { meta : meta as TypedRecord, text: extractText(part).replace(/\n/g, ' ') } }) }