mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-17 03:56:19 +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,6 +1,6 @@
|
|||
---
|
||||
import { themeConfig } from '@/config'
|
||||
import { getWalineLang } from '@/utils/i18n/ui'
|
||||
import { getWalineLang } from '@/i18n/ui'
|
||||
|
||||
const {
|
||||
serverURL = '',
|
||||
|
@ -33,8 +33,7 @@ const {
|
|||
>
|
||||
</div>
|
||||
|
||||
<!-- Not use 'is:inline' or 'define:vars' -->
|
||||
<!-- 'define:vars' ≈ 'is:inline' -->
|
||||
<!-- Not use is:inline or define:vars -->
|
||||
<script>
|
||||
import { init } from '@waline/client'
|
||||
import '@waline/client/style'
|
||||
|
|
|
@ -5,9 +5,10 @@ import themeConfig from '@/config'
|
|||
|
||||
interface Props {
|
||||
class?: string
|
||||
supportedLangs?: string[] // 文章支持的语言列表
|
||||
}
|
||||
|
||||
const { class: className } = Astro.props
|
||||
const { class: className, supportedLangs = [] } = Astro.props
|
||||
const { author } = themeConfig.site
|
||||
const { links, startYear } = themeConfig.footer
|
||||
|
||||
|
@ -26,7 +27,7 @@ const year = Number(startYear) === currentYear
|
|||
<!-- only show on desktop -->
|
||||
<div class="mb-11.5 ml-1.5 hidden gap-7 lg:flex">
|
||||
<ThemeToggle />
|
||||
<LanguageSwitcher />
|
||||
<LanguageSwitcher supportedLangs={supportedLangs} />
|
||||
</div>
|
||||
|
||||
<p>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
import themeConfig from '@/config'
|
||||
import { getPagePath } from '@/utils/i18n/path'
|
||||
import { getPagePath } from '@/i18n/path'
|
||||
|
||||
const { title, subtitle } = themeConfig.site
|
||||
const { titleSpace } = themeConfig.global
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
import themeConfig from '@/config'
|
||||
import { getPagePath } from '@/utils/i18n/path'
|
||||
import { getPagePath } from '@/i18n/path'
|
||||
|
||||
const { title, subtitle } = themeConfig.site
|
||||
const { titleSpace } = themeConfig.global
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
import { getPagePath } from '@/utils/i18n/path'
|
||||
import { ui } from '@/utils/i18n/ui'
|
||||
import { getPagePath } from '@/i18n/path'
|
||||
import { ui } from '@/i18n/ui'
|
||||
|
||||
const currentPath = Astro.url.pathname
|
||||
const { currentLang, isHome, isPost, isTag, isAbout, getLocalizedPath }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
import { themeConfig } from '@/config'
|
||||
import { isPostPage } from '@/utils/i18n/path'
|
||||
import { isPostPage } from '@/i18n/path'
|
||||
|
||||
interface Props {
|
||||
date: Date
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
---
|
||||
import { getNextLangUrl } from '@/utils/i18n/lang'
|
||||
import { getNextLangUrl, getPostNextLangUrl } from '@/i18n/lang'
|
||||
import { isPostPage } from '@/i18n/path'
|
||||
|
||||
// 获取当前路径
|
||||
interface Props {
|
||||
supportedLangs?: string[] // 文章支持的语言列表
|
||||
}
|
||||
|
||||
const { supportedLangs = [] } = Astro.props
|
||||
const currentPath = Astro.url.pathname
|
||||
const isPost = isPostPage(currentPath)
|
||||
|
||||
// 直接获取下一个语言的URL
|
||||
const nextUrl = getNextLangUrl(currentPath)
|
||||
// 根据页面类型选择不同的URL获取函数
|
||||
const nextUrl = isPost && supportedLangs.length > 0
|
||||
? getPostNextLangUrl(currentPath, supportedLangs)
|
||||
: getNextLangUrl(currentPath)
|
||||
---
|
||||
|
||||
<a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue