From 40346c3f211ef0fd70fa5a077fa1c1d55642776b Mon Sep 17 00:00:00 2001 From: wait4xx Date: Sun, 25 Oct 2026 13:11:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(books):=20=E6=B3=A5=E6=BD=AD=E7=AD=96?= =?UTF-8?q?=E5=B1=95=E8=AF=AD=E4=B8=8E=E5=9B=9E=E9=80=80=E5=A5=91=E7=BA=A6?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=EF=BC=9B=E8=87=AA=E6=89=98=E7=AE=A1=E4=BB=93?= =?UTF-8?q?=E6=98=9F=E6=A0=87=E8=AF=AD=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BooksPage 实现 schema 注释承诺的 description 回退(正文首段去记号 取 60 字)——视觉复核抓到的"文档说了代码没做"缺口 - 泥潭补人工策展语(回退之上);自托管仓星标改 self-hosted 徽标 (gitea 无 star 真值,★0 语义突兀——视觉复核次要备注) 验证: build 28 页 exit 0;dist/books 含泥潭策展语;dist/opensource self-hosted 徽标与 ★57 并存实测 Spec: 2026-10-25_add-terminal-books-admin Co-authored-by: GLM-5.3 --- content/posts/ni-tan.md | 1 + public/admin/config.yml | 3 ++- src/components/geek/ProjectWall.astro | 2 +- src/components/pages/BooksPage.astro | 10 +++++++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/content/posts/ni-tan.md b/content/posts/ni-tan.md index 93e9693..18a9b17 100644 --- a/content/posts/ni-tan.md +++ b/content/posts/ni-tan.md @@ -5,6 +5,7 @@ category: reading tags: [read] mood: '#166534' bookAuthor: '刘楚昕' +description: '迷失于黑夜时,不妨抬头看看星空。' --- ### 迷失在黑夜中时,不妨抬头看看星空;如果不知道该相信什么,人应当面对自己的良知。 diff --git a/public/admin/config.yml b/public/admin/config.yml index c55fbc1..b41d6e2 100644 --- a/public/admin/config.yml +++ b/public/admin/config.yml @@ -27,7 +27,8 @@ collections: public_folder: '' summary: '{{fields.group}} · {{fields.title}}' fields: - - { label: 标题, name: title, widget: string, required: false } + # title 必填:Astro schema z.string() 无 .optional(),omit 纪律下必需且有值才会落键(空 title 会让 main 不可构建) + - { label: 标题, name: title, widget: string, required: true } - { label: 图片, name: image, widget: image } - { label: 分组, name: group, widget: select, options: [street, landscape] } - { label: 替代文本, name: alt, widget: string, required: false } diff --git a/src/components/geek/ProjectWall.astro b/src/components/geek/ProjectWall.astro index 5212fbb..cca8fcb 100644 --- a/src/components/geek/ProjectWall.astro +++ b/src/components/geek/ProjectWall.astro @@ -39,7 +39,7 @@ try { {p.language} )} - ★ {p.stars} + {p.source === 'gitea' ? 'self-hosted' : `★ ${p.stars}`} diff --git a/src/components/pages/BooksPage.astro b/src/components/pages/BooksPage.astro index d58f3ca..cd37c34 100644 --- a/src/components/pages/BooksPage.astro +++ b/src/components/pages/BooksPage.astro @@ -12,6 +12,12 @@ const { locale = 'zh' } = Astro.props; const books = (await getCollection('posts', ({ data }) => !data.draft && data.category === 'reading' && !data.tags.includes('hidden'))) .sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()); +// 回退契约(schema 注释声称而此前未实现——视觉复核抓到的缺口): +// description 缺省取正文第一个非空段落(去 markdown 记号)前 60 字 +const firstPara = (body: string | undefined): string => { + const line = (body ?? '').split(/\n\s*\n/).map((l) => l.trim()).find((l) => l && !l.startsWith('#') && !l.startsWith('---')) ?? ''; + return line.replace(/[*_>`\[\]]/g, '').slice(0, 60); +}; const years = [...new Set(books.map((b) => b.data.pubDate.getFullYear()))].sort((a, b) => b - a); const L = { shelf: locale === 'zh' ? '书架' : 'Books', @@ -36,7 +42,9 @@ const L = {
{b.data.title} {b.data.bookAuthor && {b.data.bookAuthor}} - {b.data.description && {b.data.description}} + {(b.data.description || firstPara(b.body)) && ( + {b.data.description ?? firstPara(b.body)} + )}