---
import { SITE } from '@/consts'
import type { CollectionEntry } from 'astro:content'

interface Props {
  post: CollectionEntry<'blog'>
}

const { post } = Astro.props

const title = post.data.title || SITE.title
const description = post.data.description || SITE.description
const postUrl = new URL(post.id, SITE.href).toString()
const image = SITE.href + '/image/' + post.id + '.png';
const author = post.data.authors ? post.data.authors.join(', ') : SITE.author
---

<title>{`${title} - ${SITE.title}`}</title>
<meta name="description" content={description} />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="index, follow" />
<meta name="author" content={author} />
{post?.data.tags && <meta name="keywords" content={post.data.tags.join(', ')} />}
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={image} />
<meta property="og:image:alt" content={title} />
<meta property="og:type" content="article" />
<meta property="og:locale" content={SITE.locale} />
<meta property="og:site_name" content={SITE.title} />
<meta property="og:url" content={postUrl} />
<meta property="og:author" content={author} />
<meta property="article:published_time" content={post.data.date.toISOString()} />
<meta property="article:modified_time" content={post.data.date.toISOString()} />
<meta property="article:published" content={post.data.date.toISOString()} />
<meta property="article:publisher" content={SITE.title} />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
<meta property="twitter:image" content={image} />
<meta name="twitter:image:alt" content={title} />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:creator" content={author} />

{
  post?.data.tags &&
    post.data.tags.map((tag: string) => {
      return <meta property="article:tag" content={tag} />
    })
}

<script type="application/ld+json" is:inline set:html={JSON.stringify({
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": title,
  "description": description,
  "image": image,
  "author": {
    "@type": "Person",
    "name": author
  },
  "publisher": {
    "@type": "Organization",
    "name": SITE.title,
    "logo": {
      "@type": "ImageObject",
      "url": new URL("/favicon.ico", SITE.href).toString()
    }
  },
  "datePublished": post.data.date.toISOString(),
  "dateModified": post.data.date.toISOString(),
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": postUrl
  },
  "keywords": post?.data.tags ? post.data.tags.join(', ') : '',
  "url": postUrl
})} />