57 lines
2.9 KiB
TypeScript
57 lines
2.9 KiB
TypeScript
import { visibleNews } from './news-model'
|
|
import type { Dict } from '@/i18n'
|
|
|
|
export type CmsItem = { title?: string | null; text?: string | null }
|
|
export type CmsHome = {
|
|
mission?: string | null
|
|
directions?: CmsItem[] | null
|
|
projects?: CmsItem[] | null
|
|
collaboration?: string | null
|
|
contactEmail?: string | null
|
|
}
|
|
export type CmsNews = { id: string | number; title: string; summary?: string | null; kind?: string | null; date: string; place?: string | null; body?: string | null; imageUrl?: string | null; sourceUrl?: string | null }
|
|
|
|
export type Card = { title: string; text: string | null; tbc: boolean }
|
|
export type HomeModel = {
|
|
mission: { text: string; tbc: boolean }
|
|
directions: Card[]
|
|
projects: Card[]
|
|
news: CmsNews[]
|
|
collaboration: { text: string; email: string | null }
|
|
}
|
|
|
|
export const foundationEmail = 'qazaqlegacy@gmail.com'
|
|
// Адрес книги на Marwin; пока пусто — ссылка не показывается.
|
|
export const marwinUrl = ''
|
|
export const bookUrl = 'https://www.flip.kz/catalog?prod=6364653&utm_source=ig&utm_medium=social&utm_content=link_in_bio'
|
|
|
|
const clean = (v?: string | null) => (v && v.trim() ? v.trim() : null)
|
|
|
|
/** Собирает данные главной: редакторские значения дополняются подтверждёнными текстами словаря. */
|
|
export function buildHomeModel(cms: CmsHome | null, news: CmsNews[], t: Dict): HomeModel {
|
|
// Карточка без текста посетителю не показывается: одно название выглядит как незаконченная страница.
|
|
const cmsDirs = (cms?.directions ?? []).filter((d) => clean(d.title) && clean(d.text))
|
|
const directions: Card[] = cmsDirs.length
|
|
? cmsDirs.map((d) => ({ title: d.title!.trim(), text: clean(d.text), tbc: false }))
|
|
: t.directions.items.map((d) => ({ title: d.title, text: d.text, tbc: false }))
|
|
const projects: Card[] = (cms?.projects ?? [])
|
|
.filter((p) => clean(p.title) && clean(p.text))
|
|
.map((p) => ({ title: p.title!.trim(), text: clean(p.text), tbc: false }))
|
|
const mission = clean(cms?.mission)
|
|
return {
|
|
mission: { text: mission ?? t.mission.text, tbc: false },
|
|
directions,
|
|
projects,
|
|
news: visibleNews(news),
|
|
collaboration: { text: clean(cms?.collaboration) ?? t.collaboration.text, email: clean(cms?.contactEmail) ?? foundationEmail },
|
|
}
|
|
}
|
|
|
|
const escapeHtml = (s: string) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
|
|
|
|
/** Ссылка на почту в обёртке email_off: Cloudflare не подменяет адрес на «[email protected]». */
|
|
export function emailLinkHtml(email: string, className: string): string {
|
|
const e = escapeHtml(email)
|
|
return `<!--email_off--><a href="mailto:${e}" class="${escapeHtml(className)}">${e}</a><!--/email_off-->`
|
|
}
|