mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 11:41:17 +02:00
🚀 refactor: unify page routing files
This commit is contained in:
parent
d352b6fb65
commit
54902da6dd
19 changed files with 522 additions and 348 deletions
56
src/pages/[...index].astro
Normal file
56
src/pages/[...index].astro
Normal 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>
|
Loading…
Add table
Add a link
Reference in a new issue