---
import { site } from '../../lib/siteConfig';
import { absoluteUrl } from '../../lib/seo';

type JsonLd = Record<string, unknown> | Record<string, unknown>[];

type Props = {
  title?: string;
  description?: string;
  path?: string;
  type?: 'website' | 'article';
  publishedTime?: string;
  modifiedTime?: string;
  tags?: string[];
  jsonLd?: JsonLd;
};

const {
  title = site.title,
  description = site.description,
  path = '/',
  type = 'website',
  publishedTime,
  modifiedTime,
  tags = [],
  jsonLd
} = Astro.props;

const pageTitle = title === site.title ? site.title : `${title} | ${site.title}`;
const canonicalUrl = absoluteUrl(path);
const rssUrl = absoluteUrl('/rss.xml');
---

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>{pageTitle}</title>
<meta name="description" content={description} />
<meta name="robots" content="index,follow,max-image-preview:large,max-snippet:-1,max-video-preview:-1" />
<link rel="canonical" href={canonicalUrl} />
<link rel="alternate" type="application/rss+xml" title={`${site.title} RSS`} href={rssUrl} />
<meta property="og:site_name" content={site.title} />
<meta property="og:title" content={pageTitle} />
<meta property="og:description" content={description} />
<meta property="og:type" content={type} />
<meta property="og:url" content={canonicalUrl} />
<meta property="og:locale" content={site.language.replace('-', '_')} />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content={pageTitle} />
<meta name="twitter:description" content={description} />
{publishedTime && <meta property="article:published_time" content={publishedTime} />}
{modifiedTime && <meta property="article:modified_time" content={modifiedTime} />}
{tags.map((tag) => <meta property="article:tag" content={tag} />)}
{
  jsonLd && (
    <script type="application/ld+json" set:html={JSON.stringify(jsonLd)} />
  )
}
