mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 19:51:07 +02:00
✨ feat: complete language switching functionality and centralized page routing
This commit is contained in:
parent
4651828dd1
commit
05d3a8034b
26 changed files with 253 additions and 146 deletions
|
@ -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()
|
||||
}
|
||||
---
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue