--- import Base from '../layouts/Base.astro'; import { fetchAllFragments, blobUrl, DID } from '../lib/atproto'; import type { Fragment } from '../lib/types'; const fragments = await fetchAllFragments(); const sorted = [...fragments].reverse(); const hero = sorted.find(f => f.type === 'shot' && f.images?.length); const grid = sorted.filter(f => f !== hero); function excerpt(text: string, len: number = 120): string { return text.replace(/[#*_\[\]()>`~\-]/g, '').replace(/\n+/g, ' ').trim().slice(0, len); } // Extract top-level items from list markdown function extractListItems(content: string, max: number = 5): string[] { const items: string[] = []; for (const line of content.split('\n')) { if (items.length >= max) break; const h = line.match(/^##\s+(.+)/); if (h) { items.push(h[1].replace(/\*\*/g, '')); continue; } const b = line.match(/^[-*]\s+(.+)/); if (b && !line.startsWith(' ')) { items.push(b[1].replace(/\[([^\]]+)\]\([^)]+\)/g, '$1').replace(/\*\*/g, '').trim()); } } return items; } function countListItems(content: string): number { return content.split('\n').filter(l => l.match(/^(##\s|[-*]\s)/)).length; } function shotMeta(i: number, imgCount: number): { cls: string; isHero: boolean } { if (imgCount >= 3 && i % 12 === 0) return { cls: 'tile-hero-wide', isHero: true }; if (i % 11 === 0) return { cls: 'tile-3w', isHero: false }; if (i % 7 === 0) return { cls: 'tile-w', isHero: false }; if (i % 5 === 2) return { cls: 'tile-t', isHero: false }; return { cls: '', isHero: false }; } // Posts: mostly 1x1, rare bigger function postMeta(i: number, contentLen: number): { cls: string; showExcerpt: boolean } { if (contentLen > 2000 && i % 9 === 0) return { cls: 'tile-text-lg', showExcerpt: true }; if (contentLen > 1200 && i % 13 === 5) return { cls: 'tile-text-tall', showExcerpt: true }; return { cls: '', showExcerpt: false }; } // Build render sequence with log injected early type RenderItem = | { kind: 'log' } | { kind: 'frag'; f: Fragment; i: number }; const renderItems: RenderItem[] = []; grid.forEach((f, i) => { if (i === 5) renderItems.push({ kind: 'log' }); renderItems.push({ kind: 'frag', f, i }); }); if (grid.length <= 5) renderItems.push({ kind: 'log' }); --- nate.rip {sorted.length} fragments {sorted.filter(f => f.type === 'post').length}p {sorted.filter(f => f.type === 'shot').length}s {sorted.filter(f => f.type === 'list').length}l {hero && hero.images && ( shot #{hero.id} {hero.title} )} {renderItems.map(item => { if (item.kind === 'log') { return ( log {sorted.map(f => ( {String(f.id).padStart(2, '0')} {f.type} {f.title} {new Date(f.createdAt).toISOString().slice(0, 10)} ))} ); } const { f, i } = item; const isShot = f.type === 'shot' && f.images?.length; const isList = f.type === 'list'; // Shots if (isShot) { const { cls, isHero: promoted } = shotMeta(i, f.images!.length); if (promoted) { return ( shot #{f.id} {f.title} ); } return ( #{f.id} {f.title} ); } // Lists — unique design with extracted items if (isList) { const items = extractListItems(f.content ?? ''); const total = countListItems(f.content ?? ''); return ( list {f.title} {items.map(li => {li})} {total > items.length && +{total - items.length} more} {new Date(f.createdAt).toISOString().slice(0, 10)} ); } // Posts const { cls, showExcerpt } = postMeta(i, f.content?.length ?? 0); const padCls = !cls && i % 5 === 1 ? 'tile-airy' : ''; return ( {f.id} post {f.title} {showExcerpt && f.content && ( {excerpt(f.content, 160)} )} {new Date(f.createdAt).toISOString().slice(0, 10)} ); })}
{excerpt(f.content, 160)}