提交正式官网
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/** Recursively collect string values from nested content objects for search indexing. */
|
||||
|
||||
export function collectStrings(value: unknown, out: string[] = []): string[] {
|
||||
if (typeof value === 'string') {
|
||||
const trimmed = value.trim()
|
||||
if (trimmed) out.push(trimmed)
|
||||
return out
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((item) => collectStrings(item, out))
|
||||
return out
|
||||
}
|
||||
if (value && typeof value === 'object') {
|
||||
Object.values(value).forEach((item) => collectStrings(item, out))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
export function joinSearchText(...sources: unknown[]): string {
|
||||
return collectStrings(sources).join(' ')
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { FaqAnswerBlock, FaqItem } from '~/data/faq-content'
|
||||
import type { JsonLdNode } from '~/utils/seo'
|
||||
|
||||
function partText(part: { kind: string; value?: string; label?: string }): string {
|
||||
if (part.kind === 'text') return part.value ?? ''
|
||||
if (part.kind === 'link') return part.label ?? ''
|
||||
return ''
|
||||
}
|
||||
|
||||
function blockPlainText(block: FaqAnswerBlock): string {
|
||||
if (block.type === 'paragraph') {
|
||||
return block.parts.map(partText).join('')
|
||||
}
|
||||
|
||||
return block.items
|
||||
.map((row) => row.map(partText).join(''))
|
||||
.join(' ')
|
||||
}
|
||||
|
||||
export function faqItemPlainText(item: FaqItem): string {
|
||||
return item.blocks.map(blockPlainText).join(' ')
|
||||
}
|
||||
|
||||
export function buildFaqPageJsonLd(items: readonly FaqItem[]): JsonLdNode {
|
||||
return {
|
||||
'@type': 'FAQPage',
|
||||
mainEntity: items.map((item) => ({
|
||||
'@type': 'Question',
|
||||
name: item.question,
|
||||
acceptedAnswer: {
|
||||
'@type': 'Answer',
|
||||
text: faqItemPlainText(item)
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -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'
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { LocaleBundle, SiteLocale } from '~/types/locale'
|
||||
|
||||
export function pickLocale<T>(bundle: LocaleBundle<T>, locale: SiteLocale): T {
|
||||
if (locale === 'zh' && bundle.zh) {
|
||||
return bundle.zh
|
||||
}
|
||||
return bundle.en
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
export const DEFAULT_OG_IMAGE = '/images/hero.jpg'
|
||||
|
||||
/** 浏览器 <title> 品牌后缀(首页为完整标题,子页通过 formatPageTitle 拼接) */
|
||||
export const SITE_BRAND_TITLE: Record<'en' | 'zh', string> = {
|
||||
en: 'UMedGlobal—Health Without Borders',
|
||||
zh: '优医—让优质医疗不再因距离与语言遥不可及,帮助更多人以简单有效的方式获得健康。'
|
||||
}
|
||||
|
||||
/** 短品牌名:页头/页脚、og:site_name、JSON-LD 等 */
|
||||
export const SITE_NAME: Record<'en' | 'zh', string> = {
|
||||
en: 'UMedGlobal',
|
||||
zh: '优医'
|
||||
}
|
||||
|
||||
export function formatPageTitle(pagePart: string, locale: 'en' | 'zh'): 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: 'en' | 'zh'
|
||||
): JsonLdNode[] {
|
||||
const absoluteSiteUrl = normalizeSiteUrl(siteUrl)
|
||||
const logoPath = locale === 'zh' ? '/images/logo-zh.png' : '/images/logo-en.png'
|
||||
|
||||
return [
|
||||
{
|
||||
'@type': 'MedicalBusiness',
|
||||
'@id': `${absoluteSiteUrl}/#organization`,
|
||||
name: siteName,
|
||||
alternateName: locale === 'zh' ? 'UMedGlobal' : '优医',
|
||||
url: absoluteSiteUrl,
|
||||
logo: toAbsoluteUrl(absoluteSiteUrl, logoPath),
|
||||
image: toAbsoluteUrl(absoluteSiteUrl, DEFAULT_OG_IMAGE),
|
||||
description:
|
||||
locale === 'zh'
|
||||
? '优医是位于广州的专业医疗信息咨询机构,为国际患者对接中国三甲及 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: 'partners@umedglobal.com'
|
||||
},
|
||||
{
|
||||
'@type': 'WebSite',
|
||||
'@id': `${absoluteSiteUrl}/#website`,
|
||||
url: absoluteSiteUrl,
|
||||
name: siteName,
|
||||
publisher: { '@id': `${absoluteSiteUrl}/#organization` },
|
||||
inLanguage: locale === 'zh' ? 'zh-CN' : 'en'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
export function wrapJsonLdGraph(nodes: JsonLdNode[]): JsonLdNode {
|
||||
return {
|
||||
'@context': 'https://schema.org',
|
||||
'@graph': nodes
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user