---
interface Props {
title: string;
description?: string;
authors?: string[];
published?: string;
tags?: string[];
image?: string; // Preferred absolute URL
}
const { title, description = '', authors = [], published, tags = [], image } = Astro.props as Props;
const url = Astro.url?.toString?.() ?? '';
const site = (Astro.site ? String(Astro.site) : '') as string;
const ogImage = image && image.length > 0
? (image.startsWith('http') ? image : (site ? new URL(image, site).toString() : image))
: undefined;
const jsonLd = {
'@context': 'https://schema.org',
'@type': 'Article',
headline: title,
description: description || undefined,
datePublished: published || undefined,
author: authors.map((name) => ({ '@type': 'Person', name })),
keywords: tags.length ? tags.join(', ') : undefined,
mainEntityOfPage: url || undefined,
image: ogImage ? [ogImage] : undefined,
};
---
{description && }
{ogImage && }
{published && }
{authors.map(a => )}
{description && }
{ogImage && }