justin.deal/src/components/StructuredData.astro

89 lines
1.7 KiB
Plaintext

---
interface Props {
type: 'WebSite' | 'WebPage' | 'Article' | 'Person' | 'BreadcrumbList' | 'FAQPage';
data: Record<string, any>;
}
const { type, data } = Astro.props;
// Base structured data templates
const templates = {
WebSite: {
"@context": "https://schema.org",
"@type": "WebSite",
"name": "",
"url": "",
"description": "",
"potentialAction": {
"@type": "SearchAction",
"target": "{search_term_string}",
"query-input": "required name=search_term_string"
}
},
WebPage: {
"@context": "https://schema.org",
"@type": "WebPage",
"name": "",
"description": "",
"url": "",
"isPartOf": {
"@type": "WebSite",
"name": "",
"url": ""
}
},
Article: {
"@context": "https://schema.org",
"@type": "Article",
"headline": "",
"description": "",
"image": "",
"datePublished": "",
"dateModified": "",
"author": {
"@type": "Person",
"name": "",
"url": ""
},
"publisher": {
"@type": "Person",
"name": "",
"url": ""
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": ""
}
},
Person: {
"@context": "https://schema.org",
"@type": "Person",
"name": "",
"url": "",
"jobTitle": "",
"sameAs": []
},
BreadcrumbList: {
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": []
},
FAQPage: {
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": []
}
};
// Merge template with provided data
const structuredData = {
...templates[type],
...data
};
// Stringify the data for output
const jsonLd = JSON.stringify(structuredData, null, 2);
---
<script type="application/ld+json" set:html={jsonLd} />