diff --git a/app/archive/page.js b/app/archive/page.js new file mode 100644 index 0000000..bdb608e --- /dev/null +++ b/app/archive/page.js @@ -0,0 +1,90 @@ +import Link from 'next/link'; +import Header from '@/components/Header'; +import Footer from '@/components/Footer'; +import { listArticles } from '@/lib/engine'; +import { formatDate } from '@/lib/markdown'; +import { Archive, Clock } from 'lucide-react'; + +export const dynamic = 'force-dynamic'; +export const metadata = { title: 'Архив статей' }; + +const MONTHS = [ + 'Январь','Февраль','Март','Апрель','Май','Июнь', + 'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь', +]; + +function groupByMonth(articles) { + const groups = new Map(); + for (const a of articles) { + const d = new Date(a.published_at); + const key = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`; + if (!groups.has(key)) groups.set(key, { year: d.getFullYear(), month: d.getMonth(), items: [] }); + groups.get(key).items.push(a); + } + return Array.from(groups.entries()) + .sort(([a], [b]) => b.localeCompare(a)) + .map(([, v]) => v); +} + +export default async function ArchivePage() { + const articles = await listArticles({ limit: 500 }); + const groups = groupByMonth(articles); + + return ( + <> +
+
+
+ Архив +
+

+ Все статьи +

+

+ Полный архив. {articles.length} {articles.length === 1 ? 'материал' : 'материалов'} с момента запуска. +

+ + {articles.length === 0 && ( +

Архив пока пуст.

+ )} + +
+ {groups.map(g => ( +
+

+ {MONTHS[g.month]} {g.year} + · {g.items.length} +

+
    + {g.items.map(a => ( +
  • + + + {new Date(a.published_at).getDate().toString().padStart(2, '0')}.{(new Date(a.published_at).getMonth() + 1).toString().padStart(2, '0')} + + + {a.title} + + {a.reading_time && ( + + {a.reading_time} мин + + )} + +
  • + ))} +
+
+ ))} +
+
+