feat: complete language switching functionality and centralized page routing

This commit is contained in:
radishzzz 2025-03-14 03:30:56 +00:00
parent 4651828dd1
commit 05d3a8034b
26 changed files with 253 additions and 146 deletions

View file

@ -1,9 +1,9 @@
---
import { generateMultiLangPaths } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { generateLanguagePaths } from '@/utils/i18n/route'
export function getStaticPaths() {
return generateLanguagePaths()
return generateMultiLangPaths()
}
---

View file

@ -1,5 +1,6 @@
import type { APIContext } from 'astro'
import themeConfig from '@/config'
import { generateMultiLangPaths } from '@/i18n/route'
import { generateRSS } from '@/utils/rss'
const { moreLocale } = themeConfig.global
@ -9,7 +10,7 @@ type SupportedLanguage = typeof moreLocale[number]
// Generate static paths for all supported languages
export function getStaticPaths() {
return moreLocale.map((lang: SupportedLanguage) => ({ params: { lang } }))
return generateMultiLangPaths()
}
export async function GET({ params }: APIContext) {

View file

@ -1,13 +1,11 @@
---
import PostList from '@/components/PostList.astro'
import { themeConfig } from '@/config'
import { generateMultiLangPaths } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { getPinnedPosts, getPostsByYear } from '@/utils/content'
export function getStaticPaths() {
return themeConfig.global.moreLocale.map(lang => ({
params: { lang },
}))
return generateMultiLangPaths()
}
const { lang } = Astro.params

View file

@ -1,9 +1,9 @@
---
import Waline from '@/components/Comments/Waline.astro'
import { generateMultiLangPostPaths } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { checkSlugDuplication } from '@/utils/content'
import { generateDescription } from '@/utils/description'
import { generateMultiLangPostPaths } from '@/utils/i18n/route'
import { getCollection } from 'astro:content'
export async function getStaticPaths() {
@ -17,7 +17,7 @@ export async function getStaticPaths() {
return generateMultiLangPostPaths(posts)
}
const { post } = Astro.props
const { post, supportedLangs = [] } = Astro.props
const description = generateDescription(post)
const { Content, remarkPluginFrontmatter } = await post.render()
---
@ -26,6 +26,7 @@ const { Content, remarkPluginFrontmatter } = await post.render()
postTitle={post.data.title}
postDescription={description}
postSlug={post.slug}
supportedLangs={supportedLangs}
>
<article>
<h1>{post.data.title}</h1>

View file

@ -1,5 +1,6 @@
import type { APIContext } from 'astro'
import themeConfig from '@/config'
import { generateMultiLangPaths } from '@/i18n/route'
import { generateRSS } from '@/utils/rss'
const { moreLocale } = themeConfig.global
@ -9,7 +10,7 @@ type SupportedLanguage = typeof moreLocale[number]
// Generate static paths for all supported languages
export function getStaticPaths() {
return moreLocale.map((lang: SupportedLanguage) => ({ params: { lang } }))
return generateMultiLangPaths()
}
export async function GET({ params }: APIContext) {

View file

@ -1,7 +1,7 @@
---
import { generateMultiLangTagPaths } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { getAllTags, getPostsByTag } from '@/utils/content'
import { generateMultiLangTagPaths } from '@/utils/i18n/route'
export async function getStaticPaths() {
const tags = await getAllTags()

View file

@ -1,10 +1,10 @@
---
import { generateMultiLangPaths } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { getAllTags } from '@/utils/content'
import { generateLanguagePaths } from '@/utils/i18n/route'
export function getStaticPaths() {
return generateLanguagePaths()
return generateMultiLangPaths()
}
const { lang } = Astro.params

View file

@ -1,10 +1,10 @@
---
import Comments from '@/components/Comments/index.astro'
import PostTime from '@/components/PostTime.astro'
import { generatePostPaths } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { checkSlugDuplication } from '@/utils/content'
import { generateDescription } from '@/utils/description'
import { generatePostPaths } from '@/utils/i18n/route'
import { getCollection } from 'astro:content'
export async function getStaticPaths() {
@ -18,7 +18,7 @@ export async function getStaticPaths() {
return generatePostPaths(posts)
}
const { post } = Astro.props
const { post, supportedLangs = [] } = Astro.props
const description = generateDescription(post)
const { Content, remarkPluginFrontmatter } = await post.render()
---
@ -27,6 +27,7 @@ const { Content, remarkPluginFrontmatter } = await post.render()
postTitle={post.data.title}
postDescription={description}
postSlug={post.slug}
supportedLangs={supportedLangs}
>
<article class="heti mb-12.6">
<h1 class="post-title">

View file

@ -1,14 +1,12 @@
---
import PostList from '@/components/PostList.astro'
import { generateTagPaths } from '@/i18n/route'
import Layout from '@/layouts/Layout.astro'
import { getAllTags, getPostsByTag } from '@/utils/content'
export async function getStaticPaths() {
const tags = await getAllTags()
return tags.map(tag => ({
params: { tag },
props: { tag },
}))
return generateTagPaths(tags)
}
const { tag } = Astro.props