---
import type { GetStaticPaths } from "astro";
import { type CollectionEntry, getCollection } from "astro:content";
import { PUBLISH_DRAFTS } from "astro:env/server";
import BlogPostLayout from "@layouts/BlogPostLayout.astro";

type Props = CollectionEntry<"blog">;

type Params = {
  slug: CollectionEntry<"blog">["slug"];
};

export const getStaticPaths: GetStaticPaths = async () => {
  const posts = await getCollection("blog");
  return posts
    .filter((post) => import.meta.env.DEV || PUBLISH_DRAFTS || !post.data.isDraft)
    .map((post) => ({
      params: { slug: post.slug } satisfies Params,
      props: post satisfies Props,
    }));
};

const post = Astro.props;
const { Content } = await post.render();
---

<BlogPostLayout {...post.data}>
  <Content />
</BlogPostLayout>
