import Link from 'next/link'; import ArticleCard from './ArticleCard'; import { ArrowRight } from 'lucide-react'; /** * Группировка свежих материалов по дням: «Сегодня», «Вчера», «Эта неделя», «Ранее». * Не рендерится, если пусто. */ function groupByPeriod(articles) { const now = new Date(); const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime(); const startOfYesterday = startOfToday - 24 * 3600 * 1000; const startOfWeek = startOfToday - 7 * 24 * 3600 * 1000; const groups = { today: [], yesterday: [], week: [], earlier: [] }; for (const a of articles) { const t = new Date(a.published_at).getTime(); if (t >= startOfToday) groups.today.push(a); else if (t >= startOfYesterday) groups.yesterday.push(a); else if (t >= startOfWeek) groups.week.push(a); else groups.earlier.push(a); } return groups; } const LABELS = { today: 'Сегодня', yesterday: 'Вчера', week: 'На этой неделе', earlier: 'Ранее', }; export default function RecentBlock({ articles }) { if (!articles || articles.length === 0) return null; const groups = groupByPeriod(articles); const nonEmpty = Object.entries(groups).filter(([, arr]) => arr.length > 0); if (nonEmpty.length === 0) return null; return (

Свежие материалы

Архив
{nonEmpty.map(([key, arr]) => (

{LABELS[key]} · {arr.length}

{arr.map(a => )}
))}
); }