This commit is contained in:
2025-10-27 00:53:06 +08:00
parent 3db5a0d2e4
commit c7a650cdb7
8 changed files with 300 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
---
import { getCollection, render } from 'astro:content';
import Main from '@/layouts/mdx.astro';
// 1. 为每个集合条目生成一个新路径
export async function getStaticPaths() {
const posts = await getCollection('docs');
return posts.map((post) => ({
params: { id: post.id },
props: { post },
}));
}
type Post = {
data: { title: string };
};
// 2. 对于你的模板,你可以直接从 prop 获取条目
const { post } = Astro.props as { post: Post };
const { Content } = await render(post);
---
<Main>
<!-- <h1 slot={'header'}>{post.data.title}</h1> -->
<Content />
</Main>

View File

@@ -0,0 +1,23 @@
---
import { getCollection } from 'astro:content';
const posts = await getCollection('docs');
console.log('post', posts);
import { basename } from '@/modules/basename';
import Blank from '@/layouts/blank.astro';
---
<Blank>
<main class='max-w-3xl mx-auto'>
<h1>My posts</h1>
<ul class='p-2 m-2'>
{
posts.map((post) => (
<li>
{/* <a href={`${basename}/demo/${post.id}`}>{post.data.title}</a> */}
<a href={`/docs/${post.id}/`}>{post.data.title}</a>
</li>
))
}
</ul>
</main>
</Blank>