---
import { getImage } from "@astrojs/image";
import { getRelativeUrlByFilePath } from "~/utils/getRelativeUrlByFilePath";

import { SITE } from "~/config.mjs";

const { src: defaultImage } = await getImage({
  src: import("~/assets/images/default.png"),
  width: 1200,
  height: 628,
});

const {
  title = SITE.name,
  description = "",
  image: _image = defaultImage,
  canonical,
  noindex = false,
  nofollow = false
} = Astro.props;

const image =
  typeof _image === "string"
    ? new URL(_image, Astro.site)
    : _image && typeof _image["src"] !== "undefined"
      ? new URL(getRelativeUrlByFilePath(_image.src), Astro.site)
      : null;
---

<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />

<title>{title}</title>
<meta name="description" content={description} />
{canonical &&
<link rel="canonical" href={canonical} />}

<meta name="robots" content={`${noindex ? "noindex": "index"}, ${nofollow ? "nofollow" : "follow"}`} />

<!-- Google / Search Engine Tags -->
<meta itemprop="name" content={title} />
<meta itemprop="description" content={description} />
{image &&
<meta itemprop="image" content={image} />}

<!-- Facebook Meta Tags -->
{canonical &&
<meta property="og:url" content={canonical} />}
<meta property="og:type" content="website" />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
{image &&
<meta property="og:image" content={image} />}

<!-- Twitter Meta Tags -->
{canonical &&
<meta name="twitter:url" content={canonical} />}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
{image &&
<meta name="twitter:image" content={image} />}

<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;700&display=swap" rel="stylesheet" />

<!-- Google Site Verification -->
{SITE.googleSiteVerificationId &&
<meta name="google-site-verification" content={SITE.googleSiteVerificationId} />}