--- import { getCollection } from 'astro:content'; import '../styles/global.css'; import yaml from 'js-yaml'; import bookmarksRaw from '../data/bookmarks.yaml?raw'; import fs from 'node:fs'; import path from 'node:path'; import { getApprovedEntries, type GuestbookEntry } from '../lib/db'; interface Bookmark { date: string; title: string; url: string; } interface TxtFile { name: string; mtime: Date; } const posts = await getCollection('posts'); const sorted = posts.sort((a, b) => b.data.date.getTime() - a.data.date.getTime()); const bookmarks = (yaml.load(bookmarksRaw) as Bookmark[]) .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); // Auto-discover txt files from public/txt/ const txtDir = path.join(process.cwd(), 'public/txt'); const txtFiles: TxtFile[] = fs.existsSync(txtDir) ? fs.readdirSync(txtDir) .filter(file => file.endsWith('.txt')) .map(name => { const stat = fs.statSync(path.join(txtDir, name)); return { name, mtime: stat.mtime }; }) .sort((a, b) => b.mtime.getTime() - a.mtime.getTime()) : []; let guestbookEntries: GuestbookEntry[] = []; try { guestbookEntries = await getApprovedEntries(); } catch { // DB not available during dev without env vars } function formatDate(date: Date): string { const d = String(date.getDate()).padStart(2, '0'); const m = String(date.getMonth() + 1).padStart(2, '0'); const y = String(date.getFullYear()).slice(-2); return `${d}/${m}/${y}`; } function formatBookmarkDate(dateStr: string): string { const date = new Date(dateStr); return formatDate(date); } function extractDomain(url: string): string { try { const parsed = new URL(url); return parsed.hostname.replace(/^www\./, ''); } catch { return url; } } --- lewis m.w.
lewis m.w.  mail gh
blog
 `${formatDate(post.data.date)}    ${post.data.title}`),
  ...(sorted.length > 10 ? [`+${sorted.length - 10} more`] : [])
].join('\n')} />
txt
 `${formatDate(f.mtime)}    ${f.name}`),
  ...(txtFiles.length > 10 ? [`+${txtFiles.length - 10} more`] : [])
].join('\n')} />
bookmarks
 `${formatBookmarkDate(b.date)}    ${b.title} (${extractDomain(b.url)})`),
  ...(bookmarks.length > 10 ? [`+${bookmarks.length - 10} more`] : [])
].join('\n')} />
guestbook
{guestbookEntries.slice(0, 10).map(e => (
{formatDate(e.createdAt)} ${e.name}` : e.name} /> {e.message}
))}
{guestbookEntries.length > 10 && +{guestbookEntries.length - 10} more} sign