| 1 | import { flattenExtractedText } from "./react-text"; |
| 2 | |
| 3 | export interface FaqSchemaItem { |
| 4 | q: string; |
| 5 | a: React.ReactNode; |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * FAQPage structured data from the same Q&A pairs the FAQ page renders. |
| 10 | * `url` must be the canonical FAQ URL (en or zh), not a partial-locale fallback. |
| 11 | */ |
| 12 | export function buildFaqPageJsonLd({ |
| 13 | items, |
| 14 | url, |
| 15 | inLanguage, |
| 16 | }: { |
| 17 | items: readonly FaqSchemaItem[]; |
| 18 | url: string; |
| 19 | inLanguage: string; |
| 20 | }) { |
| 21 | return { |
| 22 | "@context": "https://schema.org", |
| 23 | "@type": "FAQPage", |
| 24 | url, |
| 25 | inLanguage, |
| 26 | mainEntity: items.map((item) => ({ |
| 27 | "@type": "Question", |
| 28 | name: item.q, |
| 29 | acceptedAnswer: { |
| 30 | "@type": "Answer", |
| 31 | text: flattenExtractedText(item.a), |
| 32 | }, |
| 33 | })), |
| 34 | }; |
| 35 | } |
| 36 |