qazaq-legacy-foundation-web/src/lib/news-model.ts
Peppa 1a58c2a4d9
All checks were successful
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 2с
peppa/test test: success за 1с
peppa/build build: success за 41с
ci / checks (pull_request) Successful in 1m22s
deploy / deploy (pull_request) Successful in 17s
QLFW-6: панель управления: проекты, фото, контакты и текст «О фонде»
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 23:33:54 +05:00

20 lines
928 B
TypeScript

import type { CmsNews } from './home-model'
export function safeWebUrl(value?: string | null): string | null {
if (!value?.trim()) return null
try {
const url = new URL(value)
return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password ? url.href : null
} catch { return null }
}
/** Фото материала: загруженное в панели, иначе безопасный адрес https. */
export function newsImage(item: CmsNews): string | null {
const c = item.cover
if (c && typeof c === 'object' && c.url) return c.url
return safeWebUrl(item.imageUrl)
}
export function visibleNews(items: CmsNews[]): CmsNews[] {
// Материал виден только целиком: заголовок, дата, текст и фото.
return items.filter(item => item.title?.trim() && Number.isFinite(Date.parse(item.date)) && item.body?.trim() && newsImage(item))
}