UNPKG

sanity-plugin-seo

Version:

Complete SEO toolkit for Sanity Studio with live scoring, AI suggestions, team workflows, and 30+ structured data types. Free and AI tiers live. Pro coming soon.

18 lines (16 loc) 522 B
/* eslint-disable @typescript-eslint/no-explicit-any */ export default function portableTextToString(value: unknown): string { if (typeof value === "string") return value; if (!Array.isArray(value)) return ""; return value .filter((block: any) => block?._type === "block") .map((block: any) => (block.children || []) .filter((child: any) => child._type === "span") .map((child: any) => child.text || "") .join(""), ) .join(" ") .replace(/\s+/g, " ") .trim(); }