98 lines
3.3 KiB
TypeScript
98 lines
3.3 KiB
TypeScript
import type { SiteLocale } from '~/types/locale'
|
|
import { LOCALE_HTML_LANG } from '~/types/locale'
|
|
|
|
export const DEFAULT_OG_IMAGE = '/images/hero.jpg'
|
|
|
|
/** 浏览器 <title> 品牌后缀(首页为完整标题,子页通过 formatPageTitle 拼接) */
|
|
export const SITE_BRAND_TITLE: Record<SiteLocale, string> = {
|
|
en: 'UMedGlobal—Health Without Borders',
|
|
zh: '优医—让优质医疗不再因距离与语言遥不可及,帮助更多人以简单有效的方式获得健康。',
|
|
ar: 'UMedGlobal—صحة بلا حدود',
|
|
ru: 'UMedGlobal—Здоровье без границ'
|
|
}
|
|
|
|
/** 短品牌名:页头/页脚、og:site_name、JSON-LD 等 */
|
|
export const SITE_NAME: Record<SiteLocale, string> = {
|
|
en: 'UMedGlobal',
|
|
zh: '优医',
|
|
ar: 'UMedGlobal',
|
|
ru: 'UMedGlobal'
|
|
}
|
|
|
|
export function formatPageTitle(pagePart: string, locale: SiteLocale): string {
|
|
return `${pagePart} | ${SITE_BRAND_TITLE[locale]}`
|
|
}
|
|
|
|
export type JsonLdNode = Record<string, unknown>
|
|
|
|
export function normalizeSiteUrl(url: string): string {
|
|
return url.replace(/\/$/, '')
|
|
}
|
|
|
|
/** 优先使用当前请求的域名,无请求上下文时回退到配置值 */
|
|
export function resolveSiteUrl(fallback: string, origin?: string | null): string {
|
|
const candidate = origin?.trim()
|
|
if (candidate && candidate !== 'null') {
|
|
return normalizeSiteUrl(candidate)
|
|
}
|
|
return normalizeSiteUrl(fallback)
|
|
}
|
|
|
|
export function toAbsoluteUrl(siteUrl: string, pathOrUrl: string): string {
|
|
if (pathOrUrl.startsWith('http://') || pathOrUrl.startsWith('https://')) {
|
|
return pathOrUrl
|
|
}
|
|
|
|
const base = normalizeSiteUrl(siteUrl)
|
|
const path = pathOrUrl.startsWith('/') ? pathOrUrl : `/${pathOrUrl}`
|
|
return `${base}${path}`
|
|
}
|
|
|
|
export function buildGlobalJsonLd(
|
|
siteUrl: string,
|
|
siteName: string,
|
|
locale: SiteLocale
|
|
): JsonLdNode[] {
|
|
const absoluteSiteUrl = normalizeSiteUrl(siteUrl)
|
|
const logoPath = locale === 'zh' ? '/images/logo-zh.png' : '/images/logo-en.png'
|
|
const isZh = locale === 'zh'
|
|
|
|
return [
|
|
{
|
|
'@type': 'MedicalBusiness',
|
|
'@id': `${absoluteSiteUrl}/#organization`,
|
|
name: siteName,
|
|
alternateName: isZh ? 'UMedGlobal' : '优医',
|
|
url: absoluteSiteUrl,
|
|
logo: toAbsoluteUrl(absoluteSiteUrl, logoPath),
|
|
image: toAbsoluteUrl(absoluteSiteUrl, DEFAULT_OG_IMAGE),
|
|
description: isZh
|
|
? '优医是位于广州的专业医疗信息咨询机构,为国际患者对接中国三甲及 JCI 认证医院,提供体检、专科诊疗、二次诊疗意见、签证与出行协调服务。'
|
|
: 'UMedGlobal is a Guangzhou-based medical concierge connecting international patients to JCI-accredited and Grade 3A hospitals in China for health screenings, specialist care, second opinions, and visa coordination.',
|
|
address: {
|
|
'@type': 'PostalAddress',
|
|
addressLocality: 'Guangzhou',
|
|
addressRegion: 'Guangdong',
|
|
addressCountry: 'CN'
|
|
},
|
|
areaServed: 'Worldwide',
|
|
email: 'info@umedglobal.com.cn'
|
|
},
|
|
{
|
|
'@type': 'WebSite',
|
|
'@id': `${absoluteSiteUrl}/#website`,
|
|
url: absoluteSiteUrl,
|
|
name: siteName,
|
|
publisher: { '@id': `${absoluteSiteUrl}/#organization` },
|
|
inLanguage: LOCALE_HTML_LANG[locale]
|
|
}
|
|
]
|
|
}
|
|
|
|
export function wrapJsonLdGraph(nodes: JsonLdNode[]): JsonLdNode {
|
|
return {
|
|
'@context': 'https://schema.org',
|
|
'@graph': nodes
|
|
}
|
|
}
|