mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-17 03:56:19 +02:00
chore: update detail
This commit is contained in:
parent
91d27dd2ba
commit
ca1abd28c1
10 changed files with 63 additions and 61 deletions
|
@ -1,7 +1,15 @@
|
|||
---
|
||||
import { themeConfig } from '@/config'
|
||||
import { getWalineLang } from '@/i18n/lang'
|
||||
import { defaultLocale } from '@/i18n/config'
|
||||
import { walineLocaleMap } from '@/i18n/ui'
|
||||
|
||||
// Theme color configuration
|
||||
const {
|
||||
light: { primary: lightPrimary, secondary: lightSecondary, background: lightBackground },
|
||||
dark: { primary: darkPrimary, secondary: darkSecondary, background: darkBackground },
|
||||
} = themeConfig.color
|
||||
|
||||
// Waline configuration
|
||||
const {
|
||||
serverURL = '',
|
||||
emoji = [],
|
||||
|
@ -9,10 +17,22 @@ const {
|
|||
imageUploader = false,
|
||||
} = themeConfig.comment?.waline ?? {}
|
||||
|
||||
// Get current path
|
||||
const currentPath = Astro.url.pathname
|
||||
const defaultLocale = themeConfig.global.locale
|
||||
const walineLang = getWalineLang(currentPath, defaultLocale)
|
||||
|
||||
// Get the language code of Waline
|
||||
function getWalineLang(currentPath: string, defaultLocale: string): string {
|
||||
// Extract language code from path
|
||||
const pathLang = Object.keys(walineLocaleMap).find(code =>
|
||||
currentPath.startsWith(`/${code}/`),
|
||||
)
|
||||
// Return found path language or default language
|
||||
const lang = pathLang || defaultLocale
|
||||
return walineLocaleMap[lang as keyof typeof walineLocaleMap]
|
||||
}
|
||||
|
||||
// Get Waline language and generate configuration
|
||||
const walineLang = getWalineLang(currentPath, defaultLocale)
|
||||
const walineConfigJson = JSON.stringify({
|
||||
serverURL,
|
||||
lang: walineLang,
|
||||
|
@ -20,12 +40,8 @@ const walineConfigJson = JSON.stringify({
|
|||
search,
|
||||
imageUploader,
|
||||
})
|
||||
|
||||
const {
|
||||
light: { primary: lightPrimary, secondary: lightSecondary, background: lightBackground },
|
||||
dark: { primary: darkPrimary, secondary: darkSecondary, background: darkBackground },
|
||||
} = themeConfig.color
|
||||
---
|
||||
|
||||
<div
|
||||
id="waline"
|
||||
class="mt-16"
|
||||
|
@ -33,6 +49,7 @@ const {
|
|||
>
|
||||
</div>
|
||||
|
||||
<!-- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
|
||||
<!-- Not use is:inline or define:vars -->
|
||||
<script>
|
||||
import { init } from '@waline/client'
|
||||
|
@ -59,6 +76,7 @@ initWaline()
|
|||
document.addEventListener('astro:after-swap', initWaline)
|
||||
</script>
|
||||
|
||||
<!-- Custom css styles >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
|
||||
<style is:global>
|
||||
#waline .wl-login-info {
|
||||
--at-apply: 'mt-0 mr-3'
|
||||
|
@ -164,6 +182,8 @@ document.addEventListener('astro:after-swap', initWaline)
|
|||
}
|
||||
</style>
|
||||
|
||||
<!-- Official css variables >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
|
||||
<!-- Docs: https://waline.js.org/reference/client/style.html -->
|
||||
<style
|
||||
define:vars={{
|
||||
lightPrimary,
|
||||
|
|
|
@ -5,7 +5,7 @@ import themeConfig from '@/config'
|
|||
|
||||
interface Props {
|
||||
class?: string
|
||||
supportedLangs?: string[] // 文章支持的语言列表
|
||||
supportedLangs: string[]
|
||||
}
|
||||
|
||||
const { class: className, supportedLangs = [] } = Astro.props
|
||||
|
|
|
@ -3,15 +3,14 @@ import { getNextLangUrl, getPostNextLangUrl } from '@/i18n/lang'
|
|||
import { isPostPage } from '@/i18n/path'
|
||||
|
||||
interface Props {
|
||||
supportedLangs?: string[] // 文章支持的语言列表
|
||||
supportedLangs: string[]
|
||||
}
|
||||
|
||||
const { supportedLangs = [] } = Astro.props
|
||||
const { supportedLangs } = Astro.props
|
||||
const currentPath = Astro.url.pathname
|
||||
const isPost = isPostPage(currentPath)
|
||||
|
||||
// 根据页面类型选择不同的URL获取函数
|
||||
const nextUrl = isPost && supportedLangs.length > 0
|
||||
const nextUrl = isPost
|
||||
? getPostNextLangUrl(currentPath, supportedLangs)
|
||||
: getNextLangUrl(currentPath)
|
||||
---
|
||||
|
@ -26,7 +25,8 @@ const nextUrl = isPost && supportedLangs.length > 0
|
|||
viewBox="0 0 24 24"
|
||||
aria-hidden="true"
|
||||
class="h-full w-full"
|
||||
fill="currentColor"
|
||||
>
|
||||
<path d="M19 21 12.3 2h-1L4.7 21l-2.5.2v.8h6.3v-.8L5.7 21l2-5.9h7.5l2 5.9-3.3.2v.8h7.9v-.8zM8 14.3l3.4-10.1 3.5 10.1z" fill="currentColor" />
|
||||
<path d="M19 21 12.3 2h-1L4.7 21l-2.5.2v.8h6.3v-.8L5.7 21l2-5.9h7.5l2 5.9-3.3.2v.8h7.9v-.8zM8 14.3l3.4-10.1 3.5 10.1z" />
|
||||
</svg>
|
||||
</a>
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
<button
|
||||
id="theme-toggle"
|
||||
aria-label="Theme Toggle Button"
|
||||
class="id-theme-toggle w-4.2 uno-button"
|
||||
aria-label="Switch light/dark theme"
|
||||
class="button-theme-toggle w-4.2 uno-button"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
aria-hidden="true"
|
||||
fill="currentColor"
|
||||
>
|
||||
<path d="m12 1c-6.1 0-11 4.9-11 11s4.9 11 11 11 11-4.9 11-11-4.9-11-11-11m0 20c-5.8 0-10.5-4-10.5-9s4.7-9 10.5-9 10.5 4 10.5 9-4.7 9-10.5 9" />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: 罗生门
|
||||
published: 1971-03-05
|
||||
published: 1915-11-05
|
||||
tags: ["芥川龙之介","近代文学"]
|
||||
lang: zh
|
||||
abbrlink: rashomon
|
||||
|
|
|
@ -154,19 +154,3 @@ export function getPostNextLangUrl(currentPath: string, supportedLangs: string[]
|
|||
// 构建下一个语言的URL
|
||||
return buildNextLangUrl(currentPath, currentLang, nextLang)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the language code of Waline
|
||||
* @param currentPath Current page path
|
||||
* @param defaultLocale Default language
|
||||
* @returns Corresponding Waline language code
|
||||
*/
|
||||
export function getWalineLang(currentPath: string, defaultLocale: string): string {
|
||||
// Extract language code from path
|
||||
const pathLang = Object.keys(walineLocaleMap).find(code =>
|
||||
currentPath.startsWith(`/${code}/`),
|
||||
)
|
||||
// Return found path language or default language
|
||||
const lang = pathLang || defaultLocale
|
||||
return walineLocaleMap[lang as keyof typeof walineLocaleMap]
|
||||
}
|
||||
|
|
|
@ -27,17 +27,14 @@ export function isHomePage(path: string) {
|
|||
const clean = cleanPath(path)
|
||||
return clean === '' || moreLocales.includes(clean)
|
||||
}
|
||||
|
||||
export function isPostPage(path: string) {
|
||||
const clean = cleanPath(path)
|
||||
return clean.startsWith('posts') || moreLocales.some(lang => clean.startsWith(`${lang}/posts`))
|
||||
}
|
||||
|
||||
export function isTagPage(path: string) {
|
||||
const clean = cleanPath(path)
|
||||
return clean.startsWith('tags') || moreLocales.some(lang => clean.startsWith(`${lang}/tags`))
|
||||
}
|
||||
|
||||
export function isAboutPage(path: string) {
|
||||
const clean = cleanPath(path)
|
||||
return clean.startsWith('about') || moreLocales.some(lang => clean.startsWith(`${lang}/about`))
|
||||
|
|
|
@ -104,7 +104,7 @@ const footerMarginClass = isPost && themeConfig.comment?.waline?.serverURL
|
|||
// Bind click event to the button
|
||||
function setupThemeToggle() {
|
||||
// Locate theme toggle button
|
||||
const themeToggleButtons = document.querySelectorAll('.id-theme-toggle')
|
||||
const themeToggleButtons = document.querySelectorAll('.button-theme-toggle')
|
||||
|
||||
// Add click listener to each button
|
||||
themeToggleButtons.forEach((button) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue