Skip to content

Commit af1534c

Browse files
committed
书架页面微调,使用 toml
1 parent ce01721 commit af1534c

13 files changed

Lines changed: 1022 additions & 98 deletions

File tree

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,10 @@ lighthouse-reports/
9999
# Font source files (large files, should be downloaded separately)
100100
fonts-source/*.otf
101101
!fonts-source/.gitkeep
102-
public/fonts/N*
102+
public/fonts/N*
103+
# Tencent Cloud EdgeOne
104+
.env
105+
.edgeone/*
106+
!.edgeone/project.json
107+
.tef_dist/*
108+

bun.lock

Lines changed: 876 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040
"astro-lightgallery": "^2.0.1",
4141
"astro-mermaid": "^1.1.0",
4242
"astro-pure": "1.3.1",
43+
"edgeone": "^1.1.20",
4344
"katex": "^0.16.22",
4445
"mermaid": "^11.12.1",
4546
"rehype-katex": "^7.0.1",
4647
"remark-breaks": "^4.0.0",
4748
"remark-math": "^6.0.0",
4849
"sharp": "^0.34.3",
50+
"toml": "^3.0.0",
4951
"typescript": "^5.8.3"
5052
},
5153
"devDependencies": {

packages/pure/components/basic/Footer.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import config from 'virtual:config'
33
44
import { getPlatformLabel, hasIcon } from '../../libs/social'
55
import { Icon } from '../user'
6+
import type { IconName } from '../../libs/icons'
67
78
const footerConf = config.footer
89
const footerLink1 = footerConf.links?.filter(({ pos }) => pos === 1) || []
910
1011
// Normalize social links data format to unified structure
1112
// Schema transform may return array or object, handle both cases
1213
const normalizeSocialLinks = (
13-
social: any
14+
social: typeof footerConf.social
1415
): Array<{ platform: string; label: string; url: string; textOnly: boolean }> => {
1516
if (!social) return []
1617
@@ -131,7 +132,7 @@ const socialLinks = normalizeSocialLinks(footerConf.social)
131132
{shouldShowText ? (
132133
<span class='text-sm'>{label}</span>
133134
) : (
134-
<Icon name={platform as any} />
135+
<Icon name={platform as IconName} />
135136
)}
136137
</a>
137138
)

public/styles/global.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
body {
55
font-family: "Noto Serif CJK", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
66
font-weight: normal;
7-
text-autospace: normal;
87
}
98

109
@font-face {

src/components/shelf/ReadingCard.astro

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ interface Props {
77
title: string;
88
type: 'book' | 'paper' | 'article';
99
status: 'read' | 'reading' | 'to-read';
10-
description?: string;
10+
description?: string; // 详细描述,最多300字
11+
summary?: string; // 一句话描述
1112
rating?: number;
1213
identifier?: string;
1314
sourceUrl?: string;
@@ -74,11 +75,13 @@ if (item.type === 'article' && item.sourceUrl) {
7475
)}
7576
</div>
7677

77-
<!-- Description -->
78+
<!-- Description - 支持长文本显示,最多300字 -->
7879
{item.description && (
79-
<p class="mt-3 border-l-2 border-border pl-3 text-sm text-muted-foreground">
80-
{item.description}
81-
</p>
80+
<div class="mt-3 border-l-2 border-border pl-3">
81+
<p class="text-sm text-muted-foreground leading-relaxed max-h-48 overflow-y-auto pr-2">
82+
{item.description}
83+
</p>
84+
</div>
8285
)}
8386

8487
<!-- Tags -->

src/components/shelf/bookshelf.json

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# 书架数据
2+
3+
[[items]]
4+
title = "潜规则"
5+
type = "book"
6+
status = "reading"
7+
summary = "揭示社会运行的潜规则,视角有些狭隘"
8+
description = """
9+
这本书里使用了比较多古代的历史案例, 试图揭示社会运行的潜规则, 但是视角有些狭隘,符合成书的 2000 年代初期的政治气候
10+
"""
11+
tags = ["历史", "社会学", "中国历史", "政治", "文化", "社会规则", "制度分析"]
12+
identifier = "9787506331744"
13+
rating = 7.1
14+
progress = 20
15+
startDate = "2025-10-25"
16+
order = 1
17+
coverImage = "/src/assets/shelf/1_qian_gui_ze.png"
18+
sourceUrl = "https://book.douban.com/subject/1025723/"
19+
links = ["igv0", "o2yb"]
20+
21+
[[items]]
22+
title = "雪国"
23+
type = "book"
24+
status = "read"
25+
summary = "名不副实的劣质作品"
26+
description = """
27+
可能是翻译的问题, 全书读完回味了几天,再来评价这本书, 也还是只能给个5 分。
28+
除了偶有的几处风景描写、对恋爱脑驹子行为的刻画很生活化之外,没有其他亮点。
29+
这本书就像川端康成在给你讲他做的梦, 作者本人沉浸其中, 读者感受却是莫名其妙,很难入戏。
30+
切入点也很奇怪是一个出轨中年人的视角, 文中的火车似乎也有这种隐喻。我个人也很难理解日本艺妓的地位,想来不会很高,给女主这样一种身份,难道是什么恶趣味?
31+
总之和诺奖级的期待相差太远,目前的 70% 左右的推荐度还是高了
32+
"""
33+
tags = ["文学", "日本文学", "小说", "川端康成", "诺贝尔文学奖"]
34+
rating = 5.3
35+
progress = 100
36+
startDate = "2025-11-03"
37+
order = 2
38+
coverImage = "/src/assets/shelf/2_xue_guo.png"
39+
sourceUrl = "https://book.douban.com/subject/1007305/"

src/components/shelf/utils.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import bookshelfData from './bookshelf.json'
1+
import bookshelfToml from './bookshelf.toml?raw'
2+
import { parse } from 'toml'
23
import { getBlogCollection, sortMDByDate } from 'astro-pure/server'
34

45
export type ShelfItem = {
56
title: string
67
type: 'book' | 'paper' | 'article'
78
status: 'read' | 'reading' | 'to-read'
8-
description?: string
9+
description?: string // 详细描述,最多300字,用于书卡展示
10+
summary?: string // 一句话描述,用于首页等简短展示场景
911
rating?: number
1012
identifier?: string
1113
sourceUrl?: string
@@ -18,11 +20,14 @@ export type ShelfItem = {
1820
endDate?: string
1921
}
2022

23+
// 解析 TOML 数据
24+
const bookshelfData = parse(bookshelfToml).items as ShelfItem[]
25+
2126
/**
2227
* Get all bookshelf items
2328
*/
2429
export function getAllBookshelfItems(): ShelfItem[] {
25-
return bookshelfData as ShelfItem[]
30+
return bookshelfData
2631
}
2732

2833
/**
@@ -99,8 +104,8 @@ export async function getTotalWords(): Promise<number> {
99104
if (post.body) {
100105
const text = post.body
101106
.replace(/<[^>]*>/g, '')
102-
.replace(/\[([^\]]*)\]\([^\)]*\)/g, '$1')
103-
.replace(/!\[([^\]]*)\]\([^\)]*\)/g, '')
107+
.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
108+
.replace(/!\[([^\]]*)\]\([^)]*\)/g, '')
104109
.replace(/[#*`_~]/g, '')
105110
.replace(/\n/g, ' ')
106111
const chineseChars = text.match(/[\u4e00-\u9fa5]/g) || []

src/content/blog/test/test_shelf.mdx

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { MdxRepl, Aside } from '@/custom/components/user';
1010
import { TabItem, Tabs } from 'astro-pure/user';
1111
import ReadingCard from '@/components/shelf/ReadingCard.astro';
1212

13-
"书架"页面是一个独立的看板, 用于展示您的阅读轨迹. 其所有内容都通过一个单独的 JSON 文件进行管理, 不依赖于任何文章的 frontmatter.
13+
"书架"页面是一个独立的看板, 用于展示您的阅读轨迹. 其所有内容都通过一个单独的 TOML 文件进行管理, 不依赖于任何文章的 frontmatter.
1414

1515
## 1. 核心配置文件
1616

17-
您需要维护的唯一文件是位于项目根目录下 `public/` 文件夹中的 `bookshelf.json`
17+
您需要维护的唯一文件是位于 `src/components/shelf/` 目录下的 `bookshelf.toml` 文件
1818

1919
## 2. 数据结构详解
2020

21-
JSON 文件是一个包含多个“阅读条目”对象的数组. 每个对象代表一张卡片, 其结构如下:
21+
TOML 文件是一个包含多个“阅读条目”对象的数组. 每个对象代表一张卡片, 其结构如下:
2222

2323
<Aside type="note" title="字段说明">
2424
| 字段 | 类型 | 是否必需 | 说明 |
@@ -40,17 +40,17 @@ import ReadingCard from '@/components/shelf/ReadingCard.astro';
4040

4141
1. **撰写笔记**: 像往常一样, 在 `src/content/blog/` 目录下创建您的 `.mdx` 笔记文件. 完成文章后, 记下您在 frontmatter 中为它设置的 `slug`.
4242

43-
2. **打开配置文件**: 打开 `public/bookshelf.json` 文件.
43+
2. **打开配置文件**: 打开 `src/components/shelf/bookshelf.toml` 文件.
4444

45-
3. **添加新条目**: 在 JSON 数组中添加一个新的对象, 代表您读完的这本书. 填写 `title`, `type`, `status` 等信息.
45+
3. **添加新条目**: 在 TOML 文件中添加一个新的 `[[items]]` 条目, 代表您读完的这本书. 填写 `title`, `type`, `status` 等信息.
4646

4747
4. **关联笔记**: 在该对象的 `links` 数组中, 添加您刚刚记下的笔记 `slug` 字符串.
4848

4949
5. **保存**: 保存文件. 网站下次构建时, 书架页面就会自动更新.
5050

5151
## 4. 卡片效果预览
5252

53-
下面是不同类型卡片的渲染效果和对应的 JSON 数据结构。
53+
下面是不同类型卡片的渲染效果和对应的 TOML 数据结构。
5454

5555
### 书籍 (Book) 示例
5656

@@ -70,17 +70,16 @@ import ReadingCard from '@/components/shelf/ReadingCard.astro';
7070
index={1}
7171
/>
7272
<Fragment slot="desc">
73-
````json
74-
{
75-
"title": "人类简史",
76-
"type": "book",
77-
"status": "read",
78-
"description": "从石器时代到人工智能, 一部宏大的人类历史.",
79-
"rating": 5,
80-
"identifier": "978-7-5086-6074-3",
81-
"tags": ["历史", "人类学"],
82-
"links": ["sapiens-note-1"]
83-
}
73+
````toml
74+
[[items]]
75+
title = "人类简史"
76+
type = "book"
77+
status = "read"
78+
description = "从石器时代到人工智能, 一部宏大的人类历史."
79+
rating = 5
80+
identifier = "978-7-5086-6074-3"
81+
tags = ["历史", "人类学"]
82+
links = ["sapiens-note-1"]
8483
````
8584
</Fragment>
8685
</MdxRepl>
@@ -103,17 +102,16 @@ import ReadingCard from '@/components/shelf/ReadingCard.astro';
103102
index={2}
104103
/>
105104
<Fragment slot="desc">
106-
````json
107-
{
108-
"title": "Attention Is All You Need",
109-
"type": "paper",
110-
"status": "read",
111-
"description": "Transformer 架构的开山之作, 奠定了现代大语言模型的基础.",
112-
"rating": 5,
113-
"identifier": "10.48550/arXiv.1706.03762",
114-
"tags": ["NLP", "Transformer"],
115-
"links": ["transformer-explained"]
116-
}
105+
````toml
106+
[[items]]
107+
title = "Attention Is All You Need"
108+
type = "paper"
109+
status = "read"
110+
description = "Transformer 架构的开山之作, 奠定了现代大语言模型的基础."
111+
rating = 5
112+
identifier = "10.48550/arXiv.1706.03762"
113+
tags = ["NLP", "Transformer"]
114+
links = ["transformer-explained"]
117115
````
118116
</Fragment>
119117
</MdxRepl>
@@ -134,15 +132,14 @@ import ReadingCard from '@/components/shelf/ReadingCard.astro';
134132
index={3}
135133
/>
136134
<Fragment slot="desc">
137-
````json
138-
{
139-
"title": "Working with TCP Sockets",
140-
"type": "article",
141-
"status": "reading",
142-
"description": "一篇关于 TCP Socket 编程的优秀文章.",
143-
"sourceUrl": "https://www.google.com",
144-
"tags": ["Network", "Socket"]
145-
}
135+
````toml
136+
[[items]]
137+
title = "Working with TCP Sockets"
138+
type = "article"
139+
status = "reading"
140+
description = "一篇关于 TCP Socket 编程的优秀文章."
141+
sourceUrl = "https://www.google.com"
142+
tags = ["Network", "Socket"]
146143
````
147144
</Fragment>
148145
</MdxRepl>

0 commit comments

Comments
 (0)