---
import '../../styles/normalize.css';
import DefaultTagPosts from '../../components/DefaultTagPosts.astro';
import YarTagPosts from '../../components/themes/yar/YarTagPosts.astro';
import { site } from '../../lib/siteConfig';
import { getPostsByTag, getTagSummaries } from '../../lib/posts';

export function getStaticPaths() {
  return getTagSummaries().map((tag) => ({
    params: { tag: tag.slug },
    props: { tag }
  }));
}

const { tag } = Astro.props;
const posts = getPostsByTag(tag.slug);
const theme = site.theme?.trim().toLowerCase() ?? 'default';
const TagPostsView = theme === 'yar' ? YarTagPosts : DefaultTagPosts;
---

<!doctype html>
<html lang={site.language}>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>{tag.name} | {site.title}</title>
    <meta name="description" content={`Posts tagged ${tag.name}`} />
  </head>
  <body>
    <TagPostsView tag={tag} posts={posts} />
  </body>
</html>
