--- import { getCollection, render } from 'astro:content'; import BaseLayout from '../layouts/BaseLayout.astro'; import { CATEGORY_COLORS } from '../consts'; export async function getStaticPaths() { const posts = await getCollection('posts'); const pages = await getCollection('pages'); // Считаем сколько постов с одинаковым {title, year} — если >1, в SEO-title // подставим полную дату, иначе только год. const titleYearCount = new Map(); for (const p of posts) { const key = `${p.data.title}|${p.data.pubDate.getFullYear()}`; titleYearCount.set(key, (titleYearCount.get(key) ?? 0) + 1); } return [ ...posts.map((p) => { const year = p.data.pubDate.getFullYear(); const key = `${p.data.title}|${year}`; const sameYearDup = (titleYearCount.get(key) ?? 1) > 1; return { params: { slug: p.data.slug }, props: { entry: p, kind: 'post' as const, sameYearDup } }; }), ...pages.map((p) => ({ params: { slug: p.data.slug }, props: { entry: p, kind: 'page' as const, sameYearDup: false } })), ]; } const { entry, kind, sameYearDup } = Astro.props; const { Content } = await render(entry); // Буквица — только для постов с телом длиннее короткого порога. const bodyLen = entry.body?.length ?? 0; const useDropCap = kind === 'post' && bodyLen > 240; const fmtDate = (d: Date) => d.toLocaleDateString('ru-RU', { year: 'numeric', month: 'long', day: 'numeric' }); // Короткая дата без "г." для SEO-title постов с одинаковым названием в одном году. const fmtDateForTitle = (d: Date) => d.toLocaleDateString('ru-RU', { year: 'numeric', month: 'long', day: 'numeric' }).replace(/\sг\.?$/, ''); const seoTitle = kind === 'post' ? `${entry.data.title} (${sameYearDup ? fmtDateForTitle(entry.data.pubDate) : entry.data.pubDate.getFullYear()})` : entry.data.title; ---
{kind === 'post' && entry.data.categories.length > 0 && ( {entry.data.categories[0]} )}

{entry.data.title}

{kind === 'post' && ( )}
{kind === 'post' && ( )}