提交正式官网

This commit is contained in:
parkiss
2026-07-09 14:35:32 +08:00
parent 5efbd6760e
commit e09f0eccda
792 changed files with 91499 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import type { SiteLocale } from '~/types/locale'
/** 去掉 /zh 前缀,得到英文默认路径 */
export function stripLocalePrefix(path: string): string {
if (path === '/zh') return '/'
if (path.startsWith('/zh/')) return path.slice(3) || '/'
return path
}
/** 根据语言生成站内路径(英文默认,中文加 /zh 前缀) */
export function toLocalePath(path: string, locale: SiteLocale): string {
const base = stripLocalePrefix(path.startsWith('/') ? path : `/${path}`)
if (locale === 'zh') {
return base === '/' ? '/zh' : `/zh${base}`
}
return base
}
export function isZhPath(path: string): boolean {
return path === '/zh' || path.startsWith('/zh/')
}
export function localeFromPath(path: string): SiteLocale {
return isZhPath(path) ? 'zh' : 'en'
}