---
import '../../styles/normalize.css';
import DefaultTagPosts from '../../components/DefaultTagPosts.astro';
import YarTagPosts from '../../components/themes/yar/YarTagPosts.astro';
import SeoHead from '../../components/seo/SeoHead.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;
const description = `${site.title} 中带有「${tag.name}」标签的文章`;
---

<!doctype html>
<html lang={site.language}>
  <head>
    <SeoHead title={tag.name} description={description} path={`/tags/${tag.slug}/`} />
  </head>
  <body>
    <TagPostsView tag={tag} posts={posts} />
  </body>
</html>
