128 lines
3.8 KiB
TypeScript
128 lines
3.8 KiB
TypeScript
import {
|
|
getHealthScreeningsDropdown,
|
|
healthScreeningsOverviewPath
|
|
} from '~/data/health-screenings-nav'
|
|
import { getPatientGuideDropdown } from '~/data/patient-guide-nav'
|
|
import { sitemapRoutes } from '~/data/sitemap-routes'
|
|
import type { MediaPublicItem } from '~/data/news-content'
|
|
import type { SiteLocale } from '~/types/locale'
|
|
import { toLocalePath } from '~/utils/locale-path'
|
|
|
|
export type SitemapPageEntry = {
|
|
label: string
|
|
path: string
|
|
href: string
|
|
external?: boolean
|
|
}
|
|
|
|
export type SitemapPageGroup = {
|
|
title: string
|
|
items: SitemapPageEntry[]
|
|
}
|
|
|
|
const coreLabels: Record<string, Record<SiteLocale, string>> = {
|
|
'/': { en: 'Home', zh: '首页' },
|
|
'/about-us': { en: 'About Us', zh: '关于我们' },
|
|
'/services': { en: 'Services', zh: '服务项目' },
|
|
'/free-assessment': { en: 'Free Assessment', zh: '免费评估' },
|
|
'/partner-with-us': { en: 'Partner With Us', zh: '合作伙伴' },
|
|
'/cases': { en: 'Success Stories', zh: '成功案例' },
|
|
'/news': { en: 'Media Center', zh: '媒体中心' },
|
|
'/faq': { en: 'FAQ', zh: '常见问题' },
|
|
'/hospitals': { en: 'Featured Hospitals', zh: '合作医院' },
|
|
'/doctors': { en: 'Featured Specialists', zh: '合作专家' },
|
|
'/sitemap': { en: 'Sitemap', zh: '站点地图' },
|
|
[healthScreeningsOverviewPath]: { en: 'Health Screenings', zh: '健康体检' }
|
|
}
|
|
|
|
function buildLabelMap(locale: SiteLocale): Map<string, string> {
|
|
const labels = new Map<string, string>()
|
|
|
|
for (const [path, names] of Object.entries(coreLabels)) {
|
|
labels.set(path, names[locale])
|
|
}
|
|
|
|
for (const item of getHealthScreeningsDropdown(locale)) {
|
|
labels.set(item.to, item.label)
|
|
}
|
|
|
|
for (const item of getPatientGuideDropdown(locale)) {
|
|
labels.set(item.to, item.label)
|
|
}
|
|
|
|
return labels
|
|
}
|
|
|
|
function toEntry(path: string, label: string, locale: SiteLocale, external = false): SitemapPageEntry {
|
|
return {
|
|
label,
|
|
path,
|
|
href: external ? path : toLocalePath(path, locale),
|
|
external,
|
|
}
|
|
}
|
|
|
|
function mediaItemToEntry(item: MediaPublicItem): SitemapPageEntry | null {
|
|
if (item.mediaType === 'article' && item.url) {
|
|
return { label: item.title, path: item.url, href: item.url, external: true }
|
|
}
|
|
const href = item.youtubeUrl || item.tiktokUrl
|
|
if (item.mediaType === 'video' && href) {
|
|
return { label: item.title, path: href, href, external: true }
|
|
}
|
|
return null
|
|
}
|
|
|
|
export function getSitemapPageGroups(
|
|
locale: SiteLocale,
|
|
mediaItems: MediaPublicItem[] = []
|
|
): SitemapPageGroup[] {
|
|
const labels = buildLabelMap(locale)
|
|
const groupTitles =
|
|
locale === 'zh'
|
|
? { main: '主要页面', screenings: '健康体检', guide: '患者指南', media: '媒体中心' }
|
|
: { main: 'Main Pages', screenings: 'Health Screenings', guide: 'Patient Guide', media: 'Media Center' }
|
|
|
|
const mainPaths = [
|
|
'/',
|
|
'/about-us',
|
|
'/services',
|
|
'/free-assessment',
|
|
'/partner-with-us',
|
|
'/cases',
|
|
'/news',
|
|
'/faq',
|
|
'/hospitals',
|
|
'/doctors'
|
|
]
|
|
|
|
const screeningPaths = sitemapRoutes
|
|
.map((route) => route.path)
|
|
.filter((path) => path.startsWith('/health-screenings'))
|
|
|
|
const guidePaths = sitemapRoutes
|
|
.map((route) => route.path)
|
|
.filter((path) => path.startsWith('/patient-guide'))
|
|
|
|
const mapItems = (paths: string[]) =>
|
|
paths
|
|
.filter((path) => labels.has(path))
|
|
.map((path) => toEntry(path, labels.get(path)!, locale))
|
|
|
|
const mediaEntries = mediaItems
|
|
.map(mediaItemToEntry)
|
|
.filter((entry): entry is SitemapPageEntry => entry != null)
|
|
|
|
const groups: SitemapPageGroup[] = [
|
|
{ title: groupTitles.main, items: mapItems(mainPaths) },
|
|
{ title: groupTitles.screenings, items: mapItems(screeningPaths) },
|
|
{ title: groupTitles.guide, items: mapItems(guidePaths) },
|
|
]
|
|
|
|
if (mediaEntries.length) {
|
|
groups.push({ title: groupTitles.media, items: mediaEntries })
|
|
}
|
|
|
|
return groups.filter((group) => group.items.length > 0)
|
|
}
|