mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
feat: allow blog posts to be organized by subdirectories
Blog posts can now be structured into subdirectories, which determine their slugs. Example: - `/src/data/blog/2025/testing.md` → `/posts/2025/testing` Directories prefixed with `_` will be excluded from the slug. Example: - `/src/data/blog/_examples/tailwind-typography.md` → `/posts/tailwind-typography` Closes #470, #366
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
---
|
||||
import { type CollectionEntry, getCollection } from "astro:content";
|
||||
import PostDetails from "@/layouts/PostDetails.astro";
|
||||
import getSortedPosts from "@/utils/getSortedPosts";
|
||||
import { getPath } from "@/utils/getPath";
|
||||
|
||||
export interface Props {
|
||||
post: CollectionEntry<"blog">;
|
||||
}
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection("blog", ({ data }) => !data.draft);
|
||||
const postResult = posts.map(post => ({
|
||||
params: { slug: getPath(post.id, post.filePath, false) },
|
||||
props: { post },
|
||||
}));
|
||||
|
||||
return postResult;
|
||||
}
|
||||
|
||||
const { post } = Astro.props;
|
||||
|
||||
const posts = await getCollection("blog");
|
||||
const sortedPosts = getSortedPosts(posts);
|
||||
---
|
||||
|
||||
<PostDetails post={post} posts={sortedPosts} />
|
||||
Reference in New Issue
Block a user