🚀 refactor: unify page routing files

This commit is contained in:
radishzzz 2025-03-14 23:13:54 +00:00
parent d352b6fb65
commit 54902da6dd
19 changed files with 522 additions and 348 deletions

View file

@ -0,0 +1,56 @@
---
import PostList from '@/components/PostList.astro'
import { allLocales, defaultLocale } from '@/i18n/config'
import Layout from '@/layouts/Layout.astro'
import { getPinnedPosts, getPostsByYear } from '@/utils/content'
export async function getStaticPaths() {
// 定义路径数组的类型
type PathItem = {
params: { index: string | undefined }
props: { lang: string }
}
const paths: PathItem[] = []
// 默认语言的首页
paths.push({
params: { index: undefined },
props: { lang: defaultLocale },
})
// 更多语言的首页
allLocales.forEach((lang: string) => {
if (lang !== defaultLocale) {
paths.push({
params: { index: lang },
props: { lang },
})
}
})
return paths
}
const { lang } = Astro.props
const pinnedPosts = await getPinnedPosts(lang)
const postsByYear = await getPostsByYear(lang)
---
<Layout>
<main>
<!-- Pinned Posts -->
{pinnedPosts.length > 0 && (
<section class="mb-7.5">
<div class="uno-decorative-line"></div>
<PostList posts={pinnedPosts} lang={lang} />
</section>
)}
<!-- Regular Posts -->
{[...postsByYear.entries()].map(([_year, posts]) => (
<section class="mb-7.5">
<div class="uno-decorative-line"></div>
<PostList posts={posts} lang={lang} />
</section>
))}
</main>
</Layout>