---
// NOTE: StarlightPage must always be the first import in the file!
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";

import { render } from "astro:content";
import { type CollectionEntry, getCollection } from "astro:content";
import Post from "../../layout/Post.astro";
import { routeConfig } from "../../utils/routeConfig";

export async function getStaticPaths() {
  const posts = await getCollection("blog");
  return posts.map((post) => ({
    params: { slug: post.id.slice(11) },
    props: post,
  }));
}

type Props = CollectionEntry<"blog">;
const post = Astro.props;

const { Content, headings } = await render(post);

Astro.locals.starlightRoute = routeConfig({
  title: post.data.title,
  slug: post.id.slice(11),
  description: post.data.description,
  toc: headings,
});
---

<StarlightPage
  frontmatter={{
    title: post.data.title,
    description: post.data.description,
    template: "splash",
    bare: true,
  }}
  hasSidebar={false}
>
  <Post {...post.data}>
    <Content />
  </Post>
</StarlightPage>
