- @intecion/ipal-kit/blocks: libraryBlocks() opt-in, one builder per block, field
builders, option merging, blockLibraryManifest, faqItemsFromLayout
- @intecion/ipal-kit/blocks/rsc: createBlockRegistry, the block components and UI
primitives (token utilities only; next/image and next/link passed in)
- @intecion/ipal-kit/templates: 10 page templates as createSeeder data
- createSeeder: { $form: title } references
- ipal-blocks eject <block>
- tests: options, rendering and a11y per block, Payload + seeding, GraphQL, admin
wording, schema snapshot (versioning), eject imports
- shorter admin labels: link "New tab", table of contents "Show contents"
Co-Authored-By: Claude Opus 5.5 <[email protected]>
18 lines
1.0 KiB
TypeScript
18 lines
1.0 KiB
TypeScript
/**
|
|
* 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<string, unknown>, { 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() }))
|
|
}
|