diff --git a/README.md b/README.md index 8d5aa81..22fe85c 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,8 @@ src/components/bookshelf-content.astro **2. 书籍** —— 来自 `public/data/books.json`,由 `bookshelf-content.astro` 在构建时 import(文件必须存在)。另外两个文件 `papers.json` / `comics.json` 对应的漫画、论文分类已经移除,文件保留但不再被引用。 +`books.json` 为空时,**统计行(N 本已读 / N 本推荐 / N 个领域)、搜索框、领域和评价筛选条会整块隐藏** —— 一排「0」加一排没东西可筛的按钮纯占地方。往 `books.json` 加了书它们会自动回来,不用改代码。手工书单和微信读书都已读完都为空时,会显示一句兜底提示。 + **两个页面共用同一个组件**,不会出现样式跑偏:`bookshelf-content.astro` 收一个 `view: "reading" | "books"`,只是决定渲染哪一块。侧栏那两行是**真链接**(带 `aria-current` 和主色高亮表示当前页),不再是页内锚点。 ## 部署 diff --git a/src/components/bookshelf-content.astro b/src/components/bookshelf-content.astro index 659377d..a33977e 100644 --- a/src/components/bookshelf-content.astro +++ b/src/components/bookshelf-content.astro @@ -63,6 +63,9 @@ const booksByCategory = allBooks.reduce>((acc, book const bookCategories = ["全部", ...Object.keys(booksByCategory), ...(finishedReading.length > 0 ? [WEREAD_CATEGORY] : [])] const bookStatuses = ["全部", "推荐", "中庸", "不行"] +/** 手工书单为空时,统计行和搜索/筛选条都没有意义,整块隐藏 */ +const hasManualBooks = allBooks.length > 0 + const bookStats = { total: allBooks.length, recommended: allBooks.filter((b) => b.fields.推荐状态 === "推荐").length, @@ -202,7 +205,11 @@ const recommendBadge = (status?: string) => {
博学而笃志,切问而近思
- {/* ---------- Stats ---------- */} + {/* ---------- Stats + Search + filters ---------- + 只有存在手工书单时才显示。books.json 为空时这三行都是「0 本已读 / + 0 本推荐 / 0 个领域」加一排没东西可筛的按钮,纯占地方。 */} + {hasManualBooks && ( + <>
{bookStats.total}本已读 {bookStats.recommended}本推荐 @@ -259,6 +266,8 @@ const recommendBadge = (status?: string) => {
+ + )} {/* ========================= Views ========================= */} @@ -359,6 +368,17 @@ const recommendBadge = (status?: string) => { )} + {/* 手工书单和微信读书都已读完都为空时的兜底 */} + {!hasManualBooks && finishedReading.length === 0 && ( +
+

书架还是空的。

+

+ 往 public/data/books.json 里加书, + 或跑一次 pnpm reading 同步微信读书。 +

+
+ )} + {/* Empty state (shared, shown when filters return nothing) */}