/** * FAQ rich results from the page's FAQ blocks — pass it to getPageJsonLd: * * getPageJsonLd(locale, slug, { faq: faqItemsFromLayout }) * * Reads the FAQ blocks by slug (default 'faq'; pass a renamed slug in `slugs`). * Empty questions and answers are skipped. */ export function faqItemsFromLayout(doc: Record, { field = 'layout', slugs = ['faq'] }: { field?: string; slugs?: string[] } = {}): { answer: string; question: string }[] { const layout = doc[field] if (!Array.isArray(layout)) {return []} return layout .filter((b): b is { blockType: string; items?: unknown } => !!b && typeof b === 'object' && slugs.includes((b as { blockType?: string }).blockType ?? '')) .flatMap((b) => (Array.isArray(b.items) ? (b.items as { answer?: unknown; question?: unknown }[]) : [])) .filter((i) => typeof i.question === 'string' && typeof i.answer === 'string' && i.question.trim() && i.answer.trim()) .map((i) => ({ answer: (i.answer as string).trim(), question: (i.question as string).trim() })) }