mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 11:41:17 +02:00
feat: giscus i18n
This commit is contained in:
parent
81ca27689f
commit
4c7a74c6c8
3 changed files with 25 additions and 5 deletions
|
@ -1,6 +1,19 @@
|
||||||
---
|
---
|
||||||
import { themeConfig } from "@/config";
|
import { defaultLocale, themeConfig } from '@/config'
|
||||||
|
import { giscusLocaleMap } from '@/i18n/config'
|
||||||
|
|
||||||
|
// Get the language code of Giscus
|
||||||
|
function getGiscusLang(currentPath: string, defaultLocale: string): string {
|
||||||
|
// Extract language code from path
|
||||||
|
const pathLang = Object.keys(giscusLocaleMap).find(code =>
|
||||||
|
currentPath.startsWith(`/${code}/`),
|
||||||
|
)
|
||||||
|
// Return found path language or default language
|
||||||
|
const lang = pathLang || defaultLocale
|
||||||
|
return giscusLocaleMap[lang as keyof typeof giscusLocaleMap]
|
||||||
|
}
|
||||||
|
|
||||||
|
const giscusLang = getGiscusLang(Astro.url.pathname, defaultLocale)
|
||||||
const {
|
const {
|
||||||
repo = "",
|
repo = "",
|
||||||
repoID = "",
|
repoID = "",
|
||||||
|
@ -8,7 +21,6 @@ const {
|
||||||
categoryID = "",
|
categoryID = "",
|
||||||
mapping = "pathname",
|
mapping = "pathname",
|
||||||
inputPosition = "top",
|
inputPosition = "top",
|
||||||
lang = "zh-CN",
|
|
||||||
loading = "lazy",
|
loading = "lazy",
|
||||||
} = themeConfig.comment?.giscus ?? {};
|
} = themeConfig.comment?.giscus ?? {};
|
||||||
---
|
---
|
||||||
|
@ -24,7 +36,7 @@ const {
|
||||||
categoryID,
|
categoryID,
|
||||||
mapping,
|
mapping,
|
||||||
inputPosition,
|
inputPosition,
|
||||||
lang,
|
giscusLang,
|
||||||
loading,
|
loading,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -53,7 +65,7 @@ const {
|
||||||
script.setAttribute("data-theme", theme);
|
script.setAttribute("data-theme", theme);
|
||||||
script.setAttribute("data-emit-metadata", "0");
|
script.setAttribute("data-emit-metadata", "0");
|
||||||
script.setAttribute("data-input-position", inputPosition);
|
script.setAttribute("data-input-position", inputPosition);
|
||||||
script.setAttribute("data-lang", lang);
|
script.setAttribute("data-lang", giscusLang);
|
||||||
script.setAttribute("data-loading", loading);
|
script.setAttribute("data-loading", loading);
|
||||||
script.crossOrigin = "anonymous";
|
script.crossOrigin = "anonymous";
|
||||||
script.async = true;
|
script.async = true;
|
||||||
|
|
|
@ -19,5 +19,14 @@ export const walineLocaleMap: Record<string, string> = {
|
||||||
'ru': 'ru-RU',
|
'ru': 'ru-RU',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const giscusLocaleMap: Record<string, string> = {
|
||||||
|
'zh': 'zh-CN',
|
||||||
|
'zh-tw': 'zh-TW',
|
||||||
|
'ja': 'ja',
|
||||||
|
'en': 'en',
|
||||||
|
'es': 'es',
|
||||||
|
'ru': 'ru',
|
||||||
|
}
|
||||||
|
|
||||||
// Supported Languages
|
// Supported Languages
|
||||||
export const supportedLangs = Object.keys(langMap).flat()
|
export const supportedLangs = Object.keys(langMap).flat()
|
||||||
|
|
1
src/types/index.d.ts
vendored
1
src/types/index.d.ts
vendored
|
@ -53,7 +53,6 @@ export interface ThemeConfig {
|
||||||
categoryID: string
|
categoryID: string
|
||||||
mapping: 'pathname' | 'url' | 'title'
|
mapping: 'pathname' | 'url' | 'title'
|
||||||
inputPosition: 'top' | 'bottom'
|
inputPosition: 'top' | 'bottom'
|
||||||
lang: Exclude<typeof supportedLangs[number], 'zh-CN'>,
|
|
||||||
loading: 'lazy' | 'embed'
|
loading: 'lazy' | 'embed'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue