diff --git a/www/src/layouts/Layout.astro b/www/src/layouts/Layout.astro index 36a569b..a2f79a3 100644 --- a/www/src/layouts/Layout.astro +++ b/www/src/layouts/Layout.astro @@ -23,7 +23,7 @@ const { title, showHeader = true, isHome = false, urls = [] } = Astro.props; {showHeader && (
-
{isHome ? lewis m.w.lewis m.w. : lewis m.w.}  mail gh rss sitemap random
+
{isHome ? lewis m.w.lewis m.w. : lewis m.w.} mail gh rss sitemap random
)} diff --git a/www/src/lib/consts.ts b/www/src/lib/consts.ts new file mode 100644 index 0000000..ab413bf --- /dev/null +++ b/www/src/lib/consts.ts @@ -0,0 +1,7 @@ +export const DEFAULT_CATEGORY = 'none'; + +export const SECTIONS = { + plaintext: 'plaintext', + bookmarks: 'bookmarks', + guestbook: 'guestbook', +} as const; diff --git a/www/src/lib/format.ts b/www/src/lib/format.ts index 2fbd80c..5a00731 100644 --- a/www/src/lib/format.ts +++ b/www/src/lib/format.ts @@ -18,11 +18,12 @@ export function formatListItem( date: Date, url: string, title: string, - options?: { pinned?: boolean; suffix?: string } + options?: { pinned?: boolean; suffix?: string; prefix?: string } ): string { const pinnedBadge = options?.pinned ? ' [pinned]' : ''; const suffix = options?.suffix ? ` ${options.suffix}` : ''; - return `${formatDate(date)} ${title}${pinnedBadge}${suffix}`; + const prefix = options?.prefix ?? ''; + return `${prefix}${formatDate(date)} ${title}${pinnedBadge}${suffix}`; } interface Sortable { diff --git a/www/src/lib/md.ts b/www/src/lib/md.ts index bc0aad3..cce083b 100644 --- a/www/src/lib/md.ts +++ b/www/src/lib/md.ts @@ -1,6 +1,7 @@ import path from 'node:path'; import type { CollectionEntry } from 'astro:content'; import { getGitDates, type GitDates } from './git'; +import { DEFAULT_CATEGORY } from './consts'; type Post = CollectionEntry<'md'>; @@ -55,15 +56,15 @@ export function organizePostsByCategory(posts: PostWithDates[], { sortAlphabetic categories: string[]; } { const grouped = posts.reduce((acc, post) => { - const category = post.data.category ?? 'md'; + const category = post.data.category ?? DEFAULT_CATEGORY; if (!acc[category]) acc[category] = []; acc[category].push(post); return acc; }, {} as Record); const categories = Object.keys(grouped).sort((a, b) => { - if (a === 'md') return -1; - if (b === 'md') return 1; + if (a === DEFAULT_CATEGORY) return -1; + if (b === DEFAULT_CATEGORY) return 1; return a.localeCompare(b); }); diff --git a/www/src/pages/index.astro b/www/src/pages/index.astro index 19c56fb..72abf9f 100644 --- a/www/src/pages/index.astro +++ b/www/src/pages/index.astro @@ -5,6 +5,7 @@ import { getApprovedEntries, type GuestbookEntry } from '../lib/db'; import { formatDate, extractDomain, formatListItem } from '../lib/format'; import { organizePostsByCategory, getSlug, enrichPostsWithDates } from '../lib/md'; import { getTxtFiles } from '../lib/txt'; +import { DEFAULT_CATEGORY, SECTIONS } from '../lib/consts'; const rawPosts = await getCollection('md'); const posts = enrichPostsWithDates(rawPosts); @@ -16,6 +17,12 @@ const bookmarks = bookmarksCollection const txtFiles = getTxtFiles(); +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)} `; +const blankPrefix = ' '.repeat(labelWidth + 2); + let guestbookEntries: GuestbookEntry[] = []; try { guestbookEntries = await getApprovedEntries(); @@ -33,35 +40,29 @@ const urls = [ {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 })).join('\n')} />
+
 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')} />
 
); })} -
- -
 formatListItem(f.date, `/${f.name}`, f.name, { pinned: f.pinned })).join('\n')} />
+
+
 formatListItem(f.date, `/${f.name}`, f.name, { pinned: f.pinned, prefix: i === 0 ? labelPrefix(SECTIONS.plaintext, `?just=${SECTIONS.plaintext}`) : blankPrefix })).join('\n')} />
 
-
- -
 formatListItem(b.data.date, b.data.url, b.data.title, { suffix: `(${extractDomain(b.data.url)})` })).join('\n')} />
+
+
 formatListItem(b.data.date, b.data.url, b.data.title, { suffix: `(${extractDomain(b.data.url)})`, prefix: i === 0 ? labelPrefix(SECTIONS.bookmarks, `?just=${SECTIONS.bookmarks}`) : blankPrefix })).join('\n')} />
 
-
- -
- {guestbookEntries.map(e => ( -
- {formatDate(e.createdAt)} - ${e.name}` : e.name} /> {e.message} -
- ))} -
-
+
+
 {
+  const prefix = i === 0 ? labelPrefix(SECTIONS.guestbook, `?just=${SECTIONS.guestbook}`) : blankPrefix;
+  const nameHtml = e.url ? `${e.name}` : `${e.name}`;
+  return `${prefix}${formatDate(e.createdAt)}  ${nameHtml} ${e.message}`;
+}).join('\n')} />
+  
     


diff --git a/www/src/styles/global.css b/www/src/styles/global.css index 3191ef4..524c5d9 100644 --- a/www/src/styles/global.css +++ b/www/src/styles/global.css @@ -101,17 +101,10 @@ section pre { } .guestbook-entries { - font-family: monospace; -} - -.guestbook-entry { - display: grid; - grid-template-columns: 8ch 1fr; - gap: 0 4ch; + white-space: pre-wrap; } .guestbook-form { margin-top: 0.5rem; - margin-left: 12ch; font-family: monospace; }