修改了微信读书的脚本
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
---
|
||||
import { formatReadingDate, type ReadingAlbum } from "@/lib/reading"
|
||||
|
||||
/**
|
||||
* 微信读书「专辑 / 有声书」卡片。
|
||||
*
|
||||
* 为什么不复用 ReadingCard:两边能拿到的字段不一样。专辑没有 progress(官方结构里
|
||||
* 就没有),文档也没给 deepLink,还少了分类、开始/读完时间。硬塞进书卡会出现
|
||||
* 「进度条永远是 0%」这种假信息,所以单独一张,底部换成「集数 / 完结状态 / 最近收听」。
|
||||
*
|
||||
* deepLink 拿不到时不渲染成 <a>,只做展示 —— 一个点不动的链接比没有链接更糟。
|
||||
*/
|
||||
interface Props {
|
||||
album: ReadingAlbum
|
||||
}
|
||||
|
||||
const { album } = Astro.props
|
||||
|
||||
const Tag = album.deepLink ? "a" : "div"
|
||||
const linkable = Boolean(album.deepLink)
|
||||
const lastListened = formatReadingDate(album.lastListenedAt)
|
||||
const meta = [album.trackCount > 0 ? `${album.trackCount} 集` : "", album.finishStatus]
|
||||
.filter(Boolean)
|
||||
.join(" · ")
|
||||
---
|
||||
|
||||
<Tag
|
||||
href={linkable ? album.deepLink : undefined}
|
||||
target={linkable ? "_blank" : undefined}
|
||||
rel={linkable ? "noopener noreferrer" : undefined}
|
||||
class:list={[
|
||||
"group flex gap-4 rounded-xl border border-border/50 bg-card p-4",
|
||||
linkable && "transition-shadow duration-300 hover:shadow-lg",
|
||||
]}
|
||||
>
|
||||
<div class="shrink-0 w-20 aspect-square rounded-lg overflow-hidden bg-surface-subtle">
|
||||
{album.cover ? (
|
||||
<img
|
||||
src={album.cover}
|
||||
alt={album.name}
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
referrerpolicy="no-referrer"
|
||||
class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
|
||||
/>
|
||||
) : (
|
||||
<div class="flex h-full w-full items-center justify-center p-2 bg-gradient-to-br from-primary/30 via-primary/20 to-primary/5">
|
||||
<p class="font-semibold text-[10px] text-foreground text-center line-clamp-4">{album.name}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div class="flex-1 min-w-0 flex flex-col">
|
||||
<h3
|
||||
class:list={[
|
||||
"font-medium text-sm text-foreground line-clamp-2 leading-snug mb-1",
|
||||
linkable && "group-hover:text-primary transition-colors",
|
||||
]}
|
||||
>
|
||||
{album.name}
|
||||
</h3>
|
||||
<p class="text-xs text-muted-foreground line-clamp-1 mb-3">{album.author}</p>
|
||||
|
||||
<div class="mt-auto space-y-1.5">
|
||||
{meta && <p class="text-[11px] text-muted-foreground/80 tabular-nums">{meta}</p>}
|
||||
<p class="text-[11px] text-muted-foreground/80 tabular-nums">
|
||||
{lastListened ? `最近收听 ${lastListened}` : "还没有收听记录"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</Tag>
|
||||
@@ -4,6 +4,7 @@ import Footer from "@/components/footer.astro"
|
||||
import { cn } from "@/lib/utils"
|
||||
import booksData from "../../public/data/books.json"
|
||||
import ReadingCard from "@/components/reading-card.astro"
|
||||
import AlbumCard from "@/components/album-card.astro"
|
||||
import { formatReadingDate, getReadingData } from "@/lib/reading"
|
||||
|
||||
/**
|
||||
@@ -26,6 +27,11 @@ const inProgressReading = readingBooks.filter((book) => !book.finished)
|
||||
const finishedReading = readingBooks.filter((book) => book.finished)
|
||||
const readingCount = inProgressReading.length
|
||||
|
||||
// 有声书专辑:与 books[] 平行的另一组数据。
|
||||
// 用 ?? [] 兜住两种情况:老版 reading.json 没有 albums 字段(--soft 回退时),
|
||||
// 以及你根本没听过有声书(服务端返回空数组)。
|
||||
const readingAlbums = reading?.albums ?? []
|
||||
|
||||
/** 「书籍」区里给微信读书已读书记一个分类名,同时作为可筛选的领域 */
|
||||
const WEREAD_CATEGORY = "微信读书"
|
||||
|
||||
@@ -194,6 +200,27 @@ const recommendBadge = (status?: string) => {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ========================= 有声书(微信读书专辑) =========================
|
||||
与 books[] 平行的一组数据,只有真的听过有声书时服务端才会返回内容。
|
||||
readingAlbums 为空就整块不渲染 —— 所以在你有第一张专辑之前,这个区块
|
||||
既不存在也不占位。数据由 scripts/fetch-reading.mjs 一并抓取。 */}
|
||||
{isReadingView && readingAlbums.length > 0 && (
|
||||
<div id="albums" class="mb-16 scroll-mt-24">
|
||||
<div class="flex flex-wrap items-end justify-between gap-x-6 gap-y-2 mb-6">
|
||||
<div>
|
||||
<div class="text-[11px] text-primary tracking-[0.22em] font-semibold uppercase mb-1.5">Collection · 02</div>
|
||||
<h2 class="text-3xl md:text-4xl font-bold font-serif tracking-tight text-foreground mb-1.5">有声书</h2>
|
||||
<div class="text-sm italic font-serif text-muted-foreground">耳朵也在读书</div>
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground tabular-nums">{readingAlbums.length} 张专辑</p>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
{readingAlbums.map((album) => <AlbumCard album={album} />)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isReadingView && (
|
||||
<>
|
||||
{/* ---------- Header ---------- */}
|
||||
|
||||
@@ -28,5 +28,13 @@ slug: impact-of-execution
|
||||
|
||||
**想到和得到之间还有一个做到**
|
||||
|
||||
有的时候我也在想这个问题,
|
||||
有的时候我也在想这个问题,**做到**突出的是个人实现的过程,是改变这个物质世界的必然。很多时候,我会选择逃避,便会以拖延的形式出现。干工作没有动力,明明知道这件事情很重要了,但是却一拖再拖。
|
||||
|
||||
内心的驱动力就是这个中间体,映射到行动上就是执行力。自己需要不断提升自己的内驱动力,在自己的精神世界里里面不断建立一个又一个里程碑,完成一个又一个目标形成正反馈,让自己成为一个高执行力的人。
|
||||
很多时候,很多事情是很难看到回报的,或者说没有那么明显的正反馈,就容易懈怠,半途而废。
|
||||
然而每个人之间的差距就会体现在这里。引用一段话:每个人,每个年龄段,每个层次都有不熟悉的领域,不精通的专业。一部分人碍于面子不懂装懂,一部分人放低自己潜心学习。这与你的年龄段,与你的层次没有关系,只与你态度发生转变有关。
|
||||
|
||||
人非生而知之,
|
||||
|
||||
|
||||
现在就是感觉自己很迷茫,不想工作,但又不得不工作。
|
||||
|
||||
+64
-35
@@ -1,19 +1,75 @@
|
||||
{
|
||||
"updatedAt": "2026-10-04T12:16:26.963Z",
|
||||
"updatedAt": "2026-10-11T08:52:01.398Z",
|
||||
"source": "weread",
|
||||
"books": [
|
||||
{
|
||||
"bookId": "3300207468",
|
||||
"title": "快乐的死(果麦经典)",
|
||||
"author": "[法]加缪",
|
||||
"category": "文学-外国文学",
|
||||
"cover": "https://cdn.weread.qq.com/weread/cover/12/cpplatform_tgx43jt54ezt7bamqcmjbk/t6_cpplatform_tgx43jt54ezt7bamqcmjbk1779878190.jpg",
|
||||
"progress": 5,
|
||||
"finished": false,
|
||||
"lastReadAt": "2026-10-08T15:27:08.000Z",
|
||||
"startedAt": null,
|
||||
"finishedAt": null,
|
||||
"readingSeconds": 262,
|
||||
"deepLink": "https://weread.qq.com/book-detail?type=1&v=66b32530813abb78ag018a22"
|
||||
},
|
||||
{
|
||||
"bookId": "3300086064",
|
||||
"title": "河西走廊",
|
||||
"author": "《河西走廊》摄制组编",
|
||||
"category": "历史-历史地理",
|
||||
"cover": "https://cdn.weread.qq.com/weread/cover/89/cpplatform_htt13rz3ky797h8pvypqq1/t6_cpplatform_htt13rz3ky797h8pvypqq11707017069.jpg",
|
||||
"progress": 0,
|
||||
"finished": false,
|
||||
"lastReadAt": "2026-10-08T12:06:21.000Z",
|
||||
"startedAt": null,
|
||||
"finishedAt": null,
|
||||
"readingSeconds": 0,
|
||||
"deepLink": "https://weread.qq.com/book-detail?type=1&v=de932a80813ab881eg014870"
|
||||
},
|
||||
{
|
||||
"bookId": "3300175025",
|
||||
"title": "此刻是春天(微信读书特别版)",
|
||||
"author": "卢思浩",
|
||||
"category": "精品小说-治愈小说",
|
||||
"cover": "https://cdn.weread.qq.com/weread/cover/4/cpplatform_3hsoybvrwapq1efqha1mvz/t6_cpplatform_3hsoybvrwapq1efqha1mvz1762325065.jpg",
|
||||
"progress": 4,
|
||||
"finished": false,
|
||||
"lastReadAt": "2026-10-08T12:05:30.000Z",
|
||||
"startedAt": "2026-01-11T10:32:09.000Z",
|
||||
"finishedAt": "2026-09-27T16:39:36.000Z",
|
||||
"readingSeconds": 295,
|
||||
"deepLink": "https://weread.qq.com/book-detail?type=1&v=b0b32630813abaadeg0157d1"
|
||||
},
|
||||
{
|
||||
"bookId": "3300095415",
|
||||
"title": "觉醒年代(全集|同名影视原著)",
|
||||
"author": "龙平平",
|
||||
"category": "历史-历史小说",
|
||||
"cover": "https://cdn.weread.qq.com/weread/cover/66/cpplatform_4opftuyz4szxsagdfgsn1i/t6_cpplatform_4opftuyz4szxsagdfgsn1i1713258044.jpg",
|
||||
"progress": 0,
|
||||
"finished": false,
|
||||
"lastReadAt": "2026-10-08T11:44:34.000Z",
|
||||
"startedAt": null,
|
||||
"finishedAt": null,
|
||||
"readingSeconds": 0,
|
||||
"deepLink": "https://weread.qq.com/book-detail?type=1&v=e6032ec0813ab8bc5g015fd3"
|
||||
},
|
||||
{
|
||||
"bookId": "182788",
|
||||
"title": "北京法源寺(文学性与思想性相结合的经典作品)",
|
||||
"author": "李敖",
|
||||
"category": "历史-历史小说",
|
||||
"cover": "https://cdn.weread.qq.com/weread/cover/16/yuewen_182788/t6_yuewen_1827881778320200.jpg",
|
||||
"progress": 51,
|
||||
"finished": false,
|
||||
"lastReadAt": "2026-10-04T10:57:59.000Z",
|
||||
"progress": 100,
|
||||
"finished": true,
|
||||
"lastReadAt": "2026-10-08T11:42:40.000Z",
|
||||
"startedAt": "2026-09-21T06:26:14.000Z",
|
||||
"finishedAt": null,
|
||||
"readingSeconds": 4379,
|
||||
"finishedAt": "2026-10-08T11:30:06.000Z",
|
||||
"readingSeconds": 11837,
|
||||
"deepLink": "https://weread.qq.com/book-detail?type=1&v=dcc3296052ca04dccdbef6c"
|
||||
},
|
||||
{
|
||||
@@ -30,20 +86,6 @@
|
||||
"readingSeconds": 14442,
|
||||
"deepLink": "https://weread.qq.com/book-detail?type=1&v=34c329807197141b34cf1db"
|
||||
},
|
||||
{
|
||||
"bookId": "3300175025",
|
||||
"title": "此刻是春天(微信读书特别版)",
|
||||
"author": "卢思浩",
|
||||
"category": "精品小说-治愈小说",
|
||||
"cover": "https://cdn.weread.qq.com/weread/cover/4/cpplatform_3hsoybvrwapq1efqha1mvz/t6_cpplatform_3hsoybvrwapq1efqha1mvz1762325065.jpg",
|
||||
"progress": 4,
|
||||
"finished": false,
|
||||
"lastReadAt": "2026-09-27T16:39:50.000Z",
|
||||
"startedAt": "2026-01-11T10:32:09.000Z",
|
||||
"finishedAt": "2026-09-27T16:39:36.000Z",
|
||||
"readingSeconds": 231,
|
||||
"deepLink": "https://weread.qq.com/book-detail?type=1&v=b0b32630813abaadeg0157d1"
|
||||
},
|
||||
{
|
||||
"bookId": "23914527",
|
||||
"title": "树莓派开始,玩转Linux",
|
||||
@@ -58,20 +100,6 @@
|
||||
"readingSeconds": 14629,
|
||||
"deepLink": "https://weread.qq.com/book-detail?type=1&v=140329d0716ce81f140468e"
|
||||
},
|
||||
{
|
||||
"bookId": "3300207468",
|
||||
"title": "快乐的死(果麦经典)",
|
||||
"author": "[法]加缪",
|
||||
"category": "文学-外国文学",
|
||||
"cover": "https://cdn.weread.qq.com/weread/cover/12/cpplatform_tgx43jt54ezt7bamqcmjbk/t6_cpplatform_tgx43jt54ezt7bamqcmjbk1779878190.jpg",
|
||||
"progress": 0,
|
||||
"finished": false,
|
||||
"lastReadAt": "2026-09-27T10:00:32.000Z",
|
||||
"startedAt": null,
|
||||
"finishedAt": null,
|
||||
"readingSeconds": 38,
|
||||
"deepLink": "https://weread.qq.com/book-detail?type=1&v=66b32530813abb78ag018a22"
|
||||
},
|
||||
{
|
||||
"bookId": "23796324",
|
||||
"title": "昨日的世界",
|
||||
@@ -380,5 +408,6 @@
|
||||
"readingSeconds": 137,
|
||||
"deepLink": "https://weread.qq.com/book-detail?type=1&v=47532ac05c659b47554a825"
|
||||
}
|
||||
]
|
||||
],
|
||||
"albums": []
|
||||
}
|
||||
|
||||
@@ -36,6 +36,39 @@ export type ReadingData = {
|
||||
updatedAt: string
|
||||
source: string
|
||||
books: ReadingBook[]
|
||||
/**
|
||||
* 专辑 / 有声书。
|
||||
*
|
||||
* 可选:`--soft` 构建路径下用的可能是更早版本的 reading.json,那时还没有这个字段。
|
||||
* 调用方一律写 `data.albums ?? []`。
|
||||
*/
|
||||
albums?: ReadingAlbum[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 一张有声书专辑。
|
||||
*
|
||||
* 字段刻意比 ReadingBook 少 —— 微信读书给专辑的原始结构里(albumInfo /
|
||||
* albumInfoExtra)**没有阅读进度,也没有 deepLink**,所以这里没有 progress,
|
||||
* 前端也不该伪造一条进度条。哪天官方补了字段,先改 scripts/fetch-reading.mjs。
|
||||
*/
|
||||
export type ReadingAlbum = {
|
||||
albumId: string
|
||||
name: string
|
||||
/** 演播 / 作者 */
|
||||
author: string
|
||||
cover: string
|
||||
/** 音频集数;取不到时为 0 */
|
||||
trackCount: number
|
||||
/** 是否已完结(原始字段 finish === 1) */
|
||||
finished: boolean
|
||||
/** 完结状态原文,如「已完结」 */
|
||||
finishStatus: string
|
||||
intro: string
|
||||
/** 最近收听时间,ISO;从没听过时为 null */
|
||||
lastListenedAt: string | null
|
||||
/** 跳转链接。官方文档未列此字段,实测可能为空串 */
|
||||
deepLink: string
|
||||
}
|
||||
|
||||
const DATA_FILE = path.join(process.cwd(), "src/data/reading.json")
|
||||
|
||||
Reference in New Issue
Block a user