feat: refactor
This commit is contained in:
parent
b83f17d087
commit
8666e5a169
57 changed files with 5734 additions and 5313 deletions
35
src/pages/posts/[category]/[slug].astro
Normal file
35
src/pages/posts/[category]/[slug].astro
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
import PostLayout from '../../../layouts/PostLayout.astro';
|
||||
import path from 'path';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const allPosts = await getCollection('posts');
|
||||
|
||||
const routes = [];
|
||||
|
||||
for (const post of allPosts) {
|
||||
const filePath = post.id;
|
||||
|
||||
const pathParts = filePath.split('/');
|
||||
const category = pathParts[0];
|
||||
|
||||
const slug = path.basename(post.id, path.extname(post.id));
|
||||
|
||||
routes.push({
|
||||
params: { category, slug },
|
||||
props: { post },
|
||||
});
|
||||
}
|
||||
|
||||
return routes;
|
||||
}
|
||||
|
||||
const { post } = Astro.props;
|
||||
|
||||
const { Content } = await post.render();
|
||||
---
|
||||
|
||||
<PostLayout frontmatter={post.data} post={post}>
|
||||
<Content />
|
||||
</PostLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue