--- 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(); const txtMaxNameLen = Math.max(...txtFiles.map(f => f.name.replace(/\.txt$/, '').length)); const visibleLabels = [...sortedCategories.filter(c => c !== DEFAULT_CATEGORY), ...Object.values(SECTIONS)]; const labelWidth = Math.max(...visibleLabels.map(l => l.length)); const labelPrefix = (label: string, href: string) => `${' '.repeat(labelWidth - label.length)}${label} `; const blankPrefix = ' '.repeat(labelWidth + 2); 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 (
 formatListItem(post.dates.created, `/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned, prefix: (!isDefault && i === 0) ? labelPrefix(category, `?just=${category}`) : blankPrefix })).join('\n')} />
); })}
 {
  const name = f.name.replace(/\.txt$/, '');
  const pad = ' '.repeat(txtMaxNameLen - name.length);
  const suffix = f.description ? `${pad} (${f.description})` : undefined;
  return formatListItem(f.date, `/${f.name}`, name, { pinned: f.pinned, suffix, prefix: i === 0 ? labelPrefix(SECTIONS.plaintext, `?just=${SECTIONS.plaintext}`) : blankPrefix });
}).join('\n')} />
 formatListItem(b.data.date, b.data.url, b.data.title, { prefix: i === 0 ? labelPrefix(SECTIONS.bookmarks, `?just=${SECTIONS.bookmarks}`) : blankPrefix })).join('\n')} />
{ const prefix = i === 0 ? labelPrefix(SECTIONS.guestbook, `?just=${SECTIONS.guestbook}`) : blankPrefix; const safeName = escapeHtml(e.name); const safeMessage = escapeHtml(e.message.replace(/\n/g, ' ')); const nameHtml = e.url ? `${safeName}` : `${safeName}`; return `${prefix}${formatDate(e.createdAt)} ${nameHtml} ${safeMessage}`; }).join('')} />