---
import '../../styles/normalize.css';
import DefaultPost from '../../components/DefaultPost.astro';
import YarPost from '../../components/themes/yar/YarPost.astro';
import SeoHead from '../../components/seo/SeoHead.astro';
import { site } from '../../lib/siteConfig';
import { absoluteUrl } from '../../lib/seo';

export function getStaticPaths() {
  const modules = import.meta.glob('../../../../../content/posts/*.md', { eager: true });
  return Object.values(modules)
    .filter((post) => post.frontmatter.status === 'published' || post.frontmatter.status === 'archived')
    .map((post) => ({
      params: { slug: post.frontmatter.slug },
      props: { post }
    }));
}

const { post } = Astro.props;
const title = post.frontmatter.title;
const theme = site.theme?.trim().toLowerCase() ?? 'default';
const PostView = theme === 'yar' ? YarPost : DefaultPost;
const description = post.frontmatter.summary ?? site.description;
const publishedTime = post.frontmatter.published_at ?? post.frontmatter.created_at;
const modifiedTime = post.frontmatter.updated_at ?? publishedTime;
const postUrl = `/posts/${post.frontmatter.slug}/`;
const tags = post.frontmatter.tags ?? [];
const jsonLd = {
  '@context': 'https://schema.org',
  '@type': 'BlogPosting',
  headline: title,
  description,
  datePublished: publishedTime,
  dateModified: modifiedTime,
  url: absoluteUrl(postUrl),
  mainEntityOfPage: absoluteUrl(postUrl),
  inLanguage: site.language,
  author: {
    '@type': 'Person',
    name: site.title
  },
  publisher: {
    '@type': 'Organization',
    name: site.title
  },
  ...(tags.length > 0 ? { keywords: tags.join(', ') } : {})
};
---

<!doctype html>
<html lang={site.language}>
  <head>
    <SeoHead
      title={title}
      description={description}
      path={postUrl}
      type="article"
      publishedTime={publishedTime}
      modifiedTime={modifiedTime}
      tags={tags}
      jsonLd={jsonLd}
    />
  </head>
  <body>
    <PostView post={post} />
  </body>
</html>
