--- import { getCollection } from 'astro:content'; import Layout from '../layouts/Layout.astro'; import { getApprovedEntries, type GuestbookEntry } from '../lib/db'; import { formatDate, formatListItem, escapeHtml } from '../lib/format'; import { organizePostsByCategory, getSlug, enrichPostsWithDates } from '../lib/md'; import { getTxtFiles } from '../lib/txt'; import { DEFAULT_CATEGORY, SECTIONS, SUBDOMAINS } from '../lib/consts'; const rawPosts = await getCollection('md'); const posts = enrichPostsWithDates(rawPosts); const { grouped, categories: sortedCategories } = organizePostsByCategory(posts); const bookmarksCollection = await getCollection('bookmarks'); const bookmarks = bookmarksCollection .sort((a, b) => b.data.date.getTime() - a.data.date.getTime()); const txtFiles = getTxtFiles(); let guestbookEntries: GuestbookEntry[] = []; try { guestbookEntries = await getApprovedEntries(); } catch { // DB not available during dev without env vars } const urls = [ ...posts.map(post => ({ url: `/${getSlug(post.id)}`, date: post.dates.created.getTime() })), ...txtFiles.map(f => ({ url: `/${f.name}`, date: f.date.getTime() })), ].sort((a, b) => b.date - a.date).map(e => e.url).concat(SUBDOMAINS); --- {sortedCategories.map(category => { const categoryPosts = grouped[category]; const isDefault = category === DEFAULT_CATEGORY; return (
{!isDefault && }
`${formatListItem(post.dates.created, `/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned })}` ).join('')} />
); })}
{ const name = f.name.replace(/\.txt$/, ''); return `${formatListItem(f.date, `/${f.name}`, name, { pinned: f.pinned })}`; }).join('')} />
`${formatListItem(b.data.date, b.data.url, b.data.title)}` ).join('')} />
{ const safeName = escapeHtml(e.name); const safeMessage = escapeHtml(e.message.replace(/\n/g, ' ')); const nameHtml = e.url ? `${safeName}` : `${safeName}`; return `${formatDate(e.createdAt)} ${nameHtml} ${safeMessage}`; }).join('')} />