---
import '../styles/global.css';
import type { ImageMetadata } from 'astro';
import { SITE_TITLE, SITE_DESCRIPTION } from '../consts';

interface Props {
	title: string;
	description: string;
	image?: ImageMetadata;
	type?: 'website' | 'article';
	publishedTime?: Date;
	modifiedTime?: Date;
}

const canonicalURL = new URL(Astro.url.pathname, Astro.site);

const {
	title,
	description,
	image,
	type = 'website',
	publishedTime,
	modifiedTime,
} = Astro.props;
---

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="generator" content={Astro.generator} />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="canonical" href={canonicalURL} />

<title>{title}</title>
<meta name="title" content={title} />
<meta name="description" content={description} />

{image && (
	<>
		<meta property="og:image" content={new URL(image.src, Astro.url)} />
		<meta name="twitter:image" content={new URL(image.src, Astro.url).toString()} />
	</>
)}

<meta property="og:type" content={type} />
<meta property="og:url" content={Astro.url} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />

<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />

{publishedTime && <meta property="article:published_time" content={publishedTime.toISOString()} />}
{modifiedTime && <meta property="article:modified_time" content={modifiedTime.toISOString()} />}
