2026-02-26 14:04:13 +08:00
|
|
|
|
import { i18n } from '@/i18n'
|
|
|
|
|
|
|
2026-02-14 11:56:08 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 统一生成页面标题,避免多处写入 document.title 产生覆盖冲突。
|
2026-02-26 14:04:13 +08:00
|
|
|
|
* 优先使用 titleKey 通过 i18n 翻译,fallback 到静态 routeTitle。
|
2026-02-14 11:56:08 +08:00
|
|
|
|
*/
|
2026-02-26 14:04:13 +08:00
|
|
|
|
export function resolveDocumentTitle(routeTitle: unknown, siteName?: string, titleKey?: string): string {
|
2026-02-14 11:56:08 +08:00
|
|
|
|
const normalizedSiteName = typeof siteName === 'string' && siteName.trim() ? siteName.trim() : 'Sub2API'
|
|
|
|
|
|
|
2026-02-26 14:04:13 +08:00
|
|
|
|
if (typeof titleKey === 'string' && titleKey.trim()) {
|
|
|
|
|
|
const translated = i18n.global.t(titleKey)
|
|
|
|
|
|
if (translated && translated !== titleKey) {
|
|
|
|
|
|
return `${translated} - ${normalizedSiteName}`
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-14 11:56:08 +08:00
|
|
|
|
if (typeof routeTitle === 'string' && routeTitle.trim()) {
|
|
|
|
|
|
return `${routeTitle.trim()} - ${normalizedSiteName}`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return normalizedSiteName
|
|
|
|
|
|
}
|