diff --git a/components/MetaTags.tsx b/components/MetaTags.tsx new file mode 100644 index 0000000..2b4b475 --- /dev/null +++ b/components/MetaTags.tsx @@ -0,0 +1,54 @@ +import { GenericResource } from "@lib/types.ts"; +import { Head } from "$fresh/runtime.ts"; + +function generateJsonLd(resource: GenericResource): string { + const baseSchema: Record = { + "@context": "https://schema.org", + "@type": resource.type.charAt(0).toUpperCase() + resource.type.slice(1), // Converts type to PascalCase + name: resource.name, + description: resource.content || resource.meta?.average || "", + keywords: resource.tags?.join(", ") || "", + image: resource.meta?.image || "/images/og-image.jpg", + }; + + if (resource.meta?.author) { + baseSchema.author = { + "@type": "Person", + name: resource.meta.author, + }; + } + + if (resource.meta?.date) { + baseSchema.datePublished = new Date(resource.meta.date).toISOString(); + } + + if (resource.meta?.rating) { + baseSchema.aggregateRating = { + "@type": "AggregateRating", + ratingValue: resource.meta.rating, + bestRating: 10, // Assuming a scale of 1 to 10 + }; + } + + return JSON.stringify(baseSchema, null, 2); +} + +export function MetaTags({ resource }: { resource: GenericResource }) { + const jsonLd = generateJsonLd(resource); + return ( + <> + + + + +