---
import type { ImageMetadata } from "astro";
interface Props {
  title?: string;
  description?: string;
  canonical?: string;
  ogImage?: string | ImageMetadata;
  ignoreTitleTemplate?: boolean;
}

import { siteConfig } from "@/config/site";

const {
  title,
  description = siteConfig.description,
  canonical,
  ogImage = siteConfig.ogImage,
  ignoreTitleTemplate = false,
} = Astro.props;

const ogImageSrc = typeof ogImage === "string" ? ogImage : ogImage.src;

const fullTitle =
  title && !ignoreTitleTemplate
    ? `${title} | ${siteConfig.name}`
    : title || siteConfig.name;
const canonicalURL =
  canonical ?? new URL(Astro.url.pathname, siteConfig.url).toString();
---

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

<!-- Primary Meta Tags -->
<title>{fullTitle}</title>
<meta name="title" content={fullTitle} />
<meta name="description" content={description} />
<meta name="author" content={siteConfig.author} />

<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content={Astro.url} />
<meta property="og:title" content={fullTitle} />
<meta property="og:description" content={description} />
<meta property="og:image" content={new URL(ogImageSrc, siteConfig.url)} />
<meta property="og:locale" content={siteConfig.locale} />

<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content={Astro.url} />
<meta property="twitter:title" content={fullTitle} />
<meta property="twitter:description" content={description} />
<meta property="twitter:image" content={new URL(ogImageSrc, siteConfig.url)} />
{
  siteConfig.twitter && (
    <meta property="twitter:creator" content={siteConfig.twitter} />
  )
}
