SanYeCao-blog/src/pages/[lang]/posts/[...slug].astro

39 lines
840 B
Text
Raw Normal View History

2026-03-24 22:28:23 +00:00
---
import { getCollection, render } from "astro:content";
import MarkdownPostLayout from "@/layouts/MarkdownPostLayout.astro";
export async function getStaticPaths() {
const posts = await getCollection("blog");
2026-03-29 19:23:23 +00:00
return posts.map((post) => {
const [lang, ...slugParts] = post.id.split("/");
return {
2026-03-24 22:28:23 +00:00
params: {
lang,
2026-03-29 19:23:23 +00:00
slug: slugParts.join("/"),
2026-03-24 22:28:23 +00:00
},
props: {
post,
lang,
},
2026-03-29 19:23:23 +00:00
};
});
2026-03-24 22:28:23 +00:00
}
const { post, lang } = Astro.props;
const { Content } = await render(post);
2026-03-29 19:23:23 +00:00
const [postLang, ...slugParts] = post.id.split("/");
const slug = slugParts.join("/");
2026-03-24 22:28:23 +00:00
---
2026-04-15 23:43:42 +00:00
<MarkdownPostLayout
frontmatter={post.data}
lang={lang}
slug={slug}
postId={post.id}
>
2026-03-24 22:28:23 +00:00
<Content />
</MarkdownPostLayout>