---
import { getCollection, type CollectionEntry } from 'astro:content';
import PostLayout from '../../layouts/PostLayout.astro';
import Counter from '../../components/Counter.vue';

// MDX 组件映射
const mdxComponents = {
  Counter,
};

// 生成所有文章的静态路径
export async function getStaticPaths() {
  const posts = await getCollection('blog');
  return posts.map((post) => ({
    params: { slug: post.slug || post.id },
    props: { post },
  }));
}

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

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

<PostLayout post={post} headings={headings}>
  <Content components={mdxComponents} />
</PostLayout>
