diff --git a/src/pages/books-preview.astro b/src/pages/books-preview.astro index 10ba73f..5a6ac80 100644 --- a/src/pages/books-preview.astro +++ b/src/pages/books-preview.astro @@ -31,6 +31,8 @@ const firstPara = (body: string | undefined): string => { return line.replace(/[*_>`[\]]/g, '').slice(0, 60); }; +/** 竖排书脊的高度有限:中文书名超过 ~11 字就必然溢出,用确定性截断代替裁切 */ +const clip = (t: string, n: number) => (t.length > n ? `${t.slice(0, n)}…` : t); const items = books.map((b) => ({ id: b.id, title: b.data.title, @@ -40,6 +42,9 @@ const items = books.map((b) => ({ mood: b.data.mood ?? 'var(--ink-4)', year: b.data.pubDate.getFullYear(), href: `/archives/${b.id}/`, + spineTitle: clip(b.data.title, 11), + spineAuthor: clip(b.data.bookAuthor ?? '', 4), + short: clip(b.data.title, 3), })); const years = [...new Set(items.map((i) => i.year))].sort((a, b) => b - a); const withCover = items.filter((i) => i.cover).length; @@ -74,8 +79,10 @@ const withCover = items.filter((i) => i.cover).length; {items.filter((i) => i.year === year).map((b) => (