42 lines
1.8 KiB
TypeScript
42 lines
1.8 KiB
TypeScript
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 }
|
|
|
|
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 }
|
|
}
|
|
|
|
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))
|
|
const directions: Card[] = cmsDirs.length
|
|
? cmsDirs.map((d) => ({ title: d.title!.trim(), text: clean(d.text), tbc: !clean(d.text) }))
|
|
: t.directions.items.map((d) => ({ title: d.title, text: d.text, tbc: true }))
|
|
const projects: Card[] = (cms?.projects ?? [])
|
|
.filter((p) => clean(p.title))
|
|
.map((p) => ({ title: p.title!.trim(), text: clean(p.text), tbc: !clean(p.text) }))
|
|
const mission = clean(cms?.mission)
|
|
return {
|
|
mission: { text: mission ?? t.mission.text, tbc: !mission },
|
|
directions,
|
|
projects,
|
|
news,
|
|
collaboration: { text: clean(cms?.collaboration) ?? t.collaboration.text, email: clean(cms?.contactEmail) },
|
|
}
|
|
}
|