Files
umed/web/data/sitemap-pages.ts
T

166 lines
6.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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, Partial<Record<SiteLocale, string>> & { en: string }> = {
'/': { en: 'Home', zh: '首页', ar: 'الرئيسية', ru: 'Главная' },
'/about-us': { en: 'About Us', zh: '关于我们', ar: 'من نحن', ru: 'О нас' },
'/services': { en: 'Services', zh: '服务项目', ar: 'الخدمات', ru: 'Услуги' },
'/free-assessment': { en: 'Free Assessment', zh: '免费评估', ar: 'تقييم مجاني', ru: 'Бесплатная оценка' },
'/partner-with-us': { en: 'Partner With Us', zh: '合作伙伴', ar: 'شاركنا التعاون', ru: 'Стать партнёром' },
'/cases': { en: 'Success Stories', zh: '成功案例', ar: 'قصص النجاح', ru: 'Истории успеха' },
'/news': { en: 'Media Center', zh: '媒体中心', ar: 'المركز الإعلامي', ru: 'Медиацентр' },
'/faq': { en: 'FAQ', zh: '常见问题', ar: 'الأسئلة الشائعة', ru: 'FAQ' },
'/hospitals': { en: 'Featured Hospitals', zh: '合作医院', ar: 'المستشفيات المميزة', ru: 'Избранные больницы' },
'/doctors': { en: 'Featured Specialists', zh: '合作专家', ar: 'الأخصائيون المميزون', ru: 'Избранные специалисты' },
'/sitemap': { en: 'Sitemap', zh: '站点地图', ar: 'خريطة الموقع', ru: 'Карта сайта' },
'/privacy-policy': { en: 'Privacy Policy', zh: '隐私政策', ar: 'سياسة الخصوصية', ru: 'Политика конфиденциальности' },
'/terms-of-use': { en: 'Terms of Use', zh: '使用条款', ar: 'شروط الاستخدام', ru: 'Условия использования' },
'/accessibility-statement': {
en: 'Accessibility Statement',
zh: '无障碍声明',
ar: 'بيان إمكانية الوصول',
ru: 'Заявление о доступности'
},
[healthScreeningsOverviewPath]: {
en: 'Health Screenings',
zh: '健康体检',
ar: 'فحوصات صحية',
ru: 'Медобследования'
}
}
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] ?? names.en)
}
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: '患者指南', legal: '法律与合规', media: '媒体中心' }
: locale === 'ar'
? {
main: 'الصفحات الرئيسية',
screenings: 'فحوصات صحية',
guide: 'دليل المريض',
legal: 'القانون والامتثال',
media: 'المركز الإعلامي'
}
: locale === 'ru'
? {
main: 'Основные страницы',
screenings: 'Медобследования',
guide: 'Гид для пациентов',
legal: 'Правовое',
media: 'Медиацентр'
}
: {
main: 'Main Pages',
screenings: 'Health Screenings',
guide: 'Patient Guide',
legal: 'Legal',
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 legalPaths = ['/privacy-policy', '/terms-of-use', '/accessibility-statement']
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) },
{ title: groupTitles.legal, items: mapItems(legalPaths) },
]
if (mediaEntries.length) {
groups.push({ title: groupTitles.media, items: mediaEntries })
}
return groups.filter((group) => group.items.length > 0)
}