fix(books): 泥潭策展语与回退契约实现;自托管仓星标语义

- 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
This commit is contained in:
wait4xandGLM-5.3 committed 2026-10-25 13:46:56 +08:00
1 parent ce587236e2
commit 40346c3f21
4 files changed
+13 -3

No files matched your search

+1
View File
@@ -5,6 +5,7 @@ category: reading
tags: [read]
mood: '#166534'
bookAuthor: '刘楚昕'
description: '迷失于黑夜时,不妨抬头看看星空。'
---
### 迷失在黑夜中时,不妨抬头看看星空;如果不知道该相信什么,人应当面对自己的良知。
+2 -1
View File
@@ -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 }
+1 -1
View File
@@ -39,7 +39,7 @@ try {
{p.language}
</span>
)}
<span class="stars">★ {p.stars}</span>
<span class="stars">{p.source === 'gitea' ? 'self-hosted' : `★ ${p.stars}`}</span>
</span>
</a>
</li>
+9 -1
View File
@@ -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 = {
<div class="bk-body">
<strong class="bk-title">{b.data.title}</strong>
{b.data.bookAuthor && <span class="bk-author">{b.data.bookAuthor}</span>}
{b.data.description && <span class="bk-desc">{b.data.description}</span>}
{(b.data.description || firstPara(b.body)) && (
<span class="bk-desc">{b.data.description ?? firstPara(b.body)}</span>
)}
</div>
</a>
</li>