---
import General from "@layouts/General.astro";
import { shouldShowPost } from "@lib/helpers";
import { getCollection } from "astro:content";

export async function getStaticPaths() {
  const blogEntries = await getCollection("blog");
  const tags = new Set(
    blogEntries
      .filter(shouldShowPost)
      .map((entry) => entry.data.tags)
      .flat(),
  );
  return Array.from(tags, (tag) => ({ params: { slug: tag }, props: { tag } }));
}

const { tag } = Astro.props;
---

<General title={`${tag} posts`}>
  {tag}
</General>
