---
import Layout from "@/layouts/Layout.astro";
import { getCollection } from "astro:content";
import type { CollectionEntry } from "astro:content";
import components from "@/components/mdx/wrapper";
import formatDate from "@/utils/format-date";

interface Props {
    post: CollectionEntry<"blog">;
}

export async function getStaticPaths() {
    const allBlogPosts = await getCollection(
        "blog",
        ({ data }) => data.draft !== true,
    );

    return allBlogPosts.map((post) => ({
        params: { slug: post.slug },
        props: { post },
    }));
}

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

<Layout title={post.data.title} description={post.data.description}>
    <article class="prose prose-invert">
        <h1>{post.data.title}</h1>
        <Content components={{ ...components }} />
        <hr />
        <p>
            <strong>Posted: </strong>
            {post.data.date && formatDate(new Date(post.data.date))}
        </p>
    </article>
</Layout>
