--- import type { ImageMetadata } from 'astro'; type Image = { src: string | ImageMetadata; alt: string; }; type SEOMetadata = { name: string; title: string; description: string; image?: Image | undefined; canonicalURL?: URL | string | undefined; locale?: string; }; type OpenGraph = Partial & { type?: string; }; type Twitter = Partial & { handle?: string; card?: 'summary' | 'summary_large_image'; }; export type Props = SEOMetadata & { og?: OpenGraph; twitter?: Twitter; }; const { name, title, description, image, locale = 'en', canonicalURL = new URL(Astro.url.pathname, Astro.site), } = Astro.props; const og = { name, title, description, canonicalURL, image, locale, type: 'website', ...(Astro.props.og ?? {}), } satisfies OpenGraph; const twitter = { name, title, description, canonicalURL, image, locale, card: 'summary_large_image', ...Astro.props.twitter, }; function normalizeImageUrl(image: string | ImageMetadata) { return typeof image === 'string' ? image : image.src; } --- {og.image && } {og.image && } {twitter.image && } {twitter.image && }