diff --git a/src/components/FAQSchema.tsx b/src/components/FAQSchema.tsx new file mode 100644 index 00000000..ef44d5a1 --- /dev/null +++ b/src/components/FAQSchema.tsx @@ -0,0 +1,37 @@ +interface FAQItem { + question: string + answer: string +} + +interface FAQSchemaProps { + items: readonly FAQItem[] +} + +export function FAQSchema({ items }: FAQSchemaProps) { + const mainEntity = items + .filter((i): i is FAQItem => Boolean(i?.question?.trim()) && Boolean(i?.answer?.trim())) + .map((item) => ({ + '@type': 'Question', + name: item.question, + acceptedAnswer: { + '@type': 'Answer', + text: item.answer, + }, + })) + + if (mainEntity.length === 0) return null + + const schema = { + '@context': 'https://schema.org', + '@type': 'FAQPage', + mainEntity, + } + + const safeSchema = JSON.stringify(schema) + .replace(//g, '\\u003e') + .replace(/&/g, '\\u0026') + + // biome-ignore lint/security/noDangerouslySetInnerHtml: JSON-LD requires innerHTML; content is escaped above + return