---
import { type CollectionEntry, getCollection } from 'astro:content'
import PostLayout from '@/layouts/PostLayout.astro'
import { render } from 'astro:content'

export async function getStaticPaths() {
  const posts = await getCollection('posts')
  return posts
    .filter((post) => !post.id.startsWith('_'))
    .map((post) => ({
      params: { slug: post.id },
      props: post
    }))
}
type Props = CollectionEntry<'posts'>

const post = Astro.props
const { Content, remarkPluginFrontmatter } = await render(post)

const readingTime = remarkPluginFrontmatter.readingTime
const toc = remarkPluginFrontmatter.toc || []
---

<PostLayout {...post.data} readingTime={readingTime} toc={toc}>
  <Content />
</PostLayout>
