update
This commit is contained in:
		
							
								
								
									
										23
									
								
								src/pages/docs/[...id].astro
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/pages/docs/[...id].astro
									
									
									
									
									
										Normal 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>
 | 
			
		||||
		Reference in New Issue
	
	Block a user