From 65383113872f98c55f62e93f3e8dcdc9bd184ede Mon Sep 17 00:00:00 2001 From: wait4xx Date: Mon, 2 Nov 2026 20:02:08 +0800 Subject: [PATCH 01/11] =?UTF-8?q?feat(content):=20=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E5=A5=91=E7=BA=A6=E4=B8=8E=E8=AE=A1=E6=95=B0=E5=BE=BD=E6=A0=87?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=EF=BC=885h=20T1=20=E5=A5=91=E7=BA=A6?= =?UTF-8?q?=E9=83=A8=E5=88=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 置顶(T1): - src/lib/post-order.ts 新增 sortPosts:置顶优先 → pubDate 倒序 → id 兜底, 把首页双轨/归档/书架四处排序口径收敛到一处 - postsSchema 增 pinned;PostList 三处渲染路径加灰阶 pin 小徽标;后台置顶开关 - 语义边界:只影响列表顺序,不改 pubDate/URL/RSS 时间语义 计数徽标(T4 契约组件): - src/components/geek/ViewMeta.astro:眼睛 = 浏览数、气泡 = 评论数, 本地 SVG + tokens 着色,不引第三方图片 - 数据只用 Artalk 匿名端点:GET comments?limit=1 一次拿到 count 与 page.pv; page 模式先 POST pages/pv 计一次浏览,readonly 模式零写入 - SSR 占位「–」:无 JS/接口失败不显示 0 误导读者 验证: pnpm astro build 48 页 exit 0;config-check 208 字段/65 hint 全过; sortPosts 四调用点替换后构建通过 Spec: 2026-11-02_blog-5h-content-social (T1 契约) Co-authored-by: GLM-5.3 --- .../2026-11-02_blog-5h-content-social/spec.md | 91 +++++++++ .../tasks.md | 44 +++++ public/admin/config.yml | 1 + src/components/PostList.astro | 21 ++ src/components/geek/ViewMeta.astro | 179 ++++++++++++++++++ src/components/pages/BooksPage.astro | 6 +- src/components/pages/HomePage.astro | 8 +- src/content.config.ts | 2 + src/i18n/ui.ts | 3 + src/lib/post-order.ts | 31 +++ src/pages/archives/index.astro | 6 +- src/pages/en/archives/index.astro | 5 +- 12 files changed, 388 insertions(+), 9 deletions(-) create mode 100644 .spec/specs/2026-11-02_blog-5h-content-social/spec.md create mode 100644 .spec/specs/2026-11-02_blog-5h-content-social/tasks.md create mode 100644 src/components/geek/ViewMeta.astro create mode 100644 src/lib/post-order.ts diff --git a/.spec/specs/2026-11-02_blog-5h-content-social/spec.md b/.spec/specs/2026-11-02_blog-5h-content-social/spec.md new file mode 100644 index 0000000..e6dc659 --- /dev/null +++ b/.spec/specs/2026-11-02_blog-5h-content-social/spec.md @@ -0,0 +1,91 @@ +# Phase 5h:内容表达能力与社交反馈 - 项目范围 + + + +## 1. 问题定义 +- **项目目标**:①文章支持置顶(作者指定优先)②瞬间的文字与文章同级表达力(字体可换、颜色可换、多段落/列表/强调)③瞬间每条可独立评论 ④浏览量与评论数用统一的「眼睛/气泡」计数徽标呈现(对齐开源页 GitHub 档案的眼图标语汇)⑤开源页开篇从 GitHub README 直接移植导致:`
` 内联对齐失效、shields/vercel/snake/komarev 等外链图在慢网下空白破版、README 的「About Me」与开源页主题无关——重构为原生组件并从 README 解耦 ⑥关于页承接读完 README 后仍想保留的个人叙述 ⑦新增一篇「写作模板」示例文章,把可用排版能力一次演示完 +- **目标用户**:站长(写得更自由,少打字面 HTML)、读者(读到更丰富且不破版的页) +- **核心价值**:内容表达力与后台编辑力对上,同时把外链依赖与版式事故面砍掉;社交反馈(浏览/评论)在灰阶体系内可量化可见 + +## 2. 假设与待确认 + +### 2.1 已确认事实 +- Artalk v2 匿名可读:`GET /artalk/api/v2/comments?site_name=…&page_key=…&limit=1` 返回 `{count, roots_count, page:{pv}}`(生产实测,2026-11-02);`POST /artalk/api/v2/pages/pv` 返回 `{pv}`(现有组件在用) +- 富文本管线已存在且已净化:`renderRich`(markdown + rehype-content-sanitize 标签/属性/协议三层白名单)与 `rehype-class-whitelist`(35 项排版类,单一事实源 `public/admin/typography-classes.js`) +- 现有 6 自托管字族(含 font-huiwen 子集化 420KB 单页)与 16 彩色语义类 + 4 灰阶语义类 +- 开源页 README 现由 `intro_from: "off"` 关闭,缓存文件 `content/.github-readme.md`(3138B)含 6 类外链图(readme-typing-svg / shields.io / github-readme-stats / streak-stats / activity-graph / snake / komarev) +- 首页/归档/书架三处列表排序均为 `pubDate` 降序,无置顶概念(`grep pinned` 只命中开源页仓库白名单) + +### 2.2 关键假设 +- 瞬间富文本走与全站文案同一条净化管线即可满足「字体/颜色可换」且不引入 XSS 面(危险标签整棵丢弃、协议白名单 http/https/mailto) +- 每条瞬间一个 Artalk page_key(`/moments/#`)不会与页面级 pv 冲突;Artalk 实例按需挂载(展开才 init)可避免 "one page one Artalk" 的全局实例冲突 +- 开源页可用本地数据(已有 repo 元数据 + GitHub GraphQL 拉取)自绘 followers/stars/语言占比,无需任何第三方徽章服务 + +### 2.3 待确认问题 +- [x] 瞬间文字是否允许 HTML 类名(字体/颜色)→ 用户原话「字体可换、颜色可换等」,按富文本管线放行 35 项白名单类 +- [x] 开源页要不要与 README 完全一致 → 用户原话「可以自行进行美化,无需完全一致」,按原生组件重构 +- [x] About Me 类内容放哪 → 用户原话「有些可以直接移植到关于页面中」,迁到 about.yaml blocks + +### 2.4 可选解释与取舍 +- 置顶只作用于列表排序与视觉标记,不改 URL / 不改 pubDate 语义(订阅源按时间仍正确) +- 计数徽标一次只拉当前页的 pv(POST 计一次)与评论数(GET 读);瞬间列表按可视区懒拉,避免 N 次请求把首屏拖慢 +- 开源页保留 `intro_from` 开关作为 compat,但默认 off 且文档标注「不推荐」;README 渲染通道不删除(后台仍可切回) + +### 2.5 已证伪路径 +- 直接渲染 README HTML 并试图用 CSS 修 `align="center"`:内联属性与 sanitize 的交互不可控,且外链图仍会空白破版 → 弃,改原生组件 +- 每条瞬间都 init 一个 Artalk 实例常驻:内存与请求成本高、且 Artalk 对多实例的支持未验证 → 改为展开时挂载 +- 用第三方徽章服务显示访客数(komarev 等):外链依赖 + 灰阶体系外颜色 → 弃,用 Artalk pv 自绘 + +## 3. 功能范围 + +### 3.1 核心功能(MVP) +- [ ] T1 文章置顶:posts/postsEn schema `pinned`、四处列表排序(首页双轨/归档/书架)、视觉标记(灰阶 pin)、后台开关 +- [ ] T2 瞬间富文本:moments `text` 支持 markdown + 白名单排版类(字体/颜色/强调/多段/列表)、净化管线复用、后台改 markdown 编辑器、旧纯文本零回归 +- [ ] T3 瞬间逐条评论:每条 moment 独立 page_key 的 Artalk 评论区(折叠、展开时挂载)、评论数联动、双语页共用同一 key +- [ ] T4 计数徽标:新增 `ViewMeta` 组件(眼睛图标 = 浏览数、气泡图标 = 评论数),接入文章页/瞬间页/关于页/开源页 +- [ ] T5 开源页重构:原生 GitHub 档案卡(头像/名字/关注者/星标/语言占比,本地数据自绘)替换 README 外链图;`align` 失效与破图问题消失;README 通道降级为可选 +- [ ] T6 关于页承接:把 README 的 About Me / Find Me 迁为 about.yaml blocks(prose + linklist),开源页只留开源相关 +- [ ] T7 写作模板示例:中英双语示例文章,演示标题层级/彩色强调/字族/引用/代码/图/表/链接卡片/折叠,并作为置顶功能的活样本;docs 与后台 hint 同步 + +### 3.2 扩展功能 +- 无 + +### 3.3 不在范围内 +- 评论回复通知/邮件推送、点赞/投票、阅读进度、站点级总访问量统计(Artalk 无匿名聚合端点) + +## 4. 最小实现路径 +- 最简单可行方案:置顶先用 boolean + 排序键;瞬间富文本直接把 `text` 交给既有 `renderRich`;评论用现有 Artalk 组件克隆一份带折叠的;计数徽标只做 pv + count 两个数 +- 暂不引入:置顶权重/多级置顶、瞬间的图片轮播、评论楼中楼定制、开源页的实时 Star 曲线 +- 不做的抽象:通用「内容社交层」框架(只服务现有页面) + +## 5. 技术决策 +- 技术栈:Astro 7.4.4 + zod schema + Artalk v2 HTTP API + GitHub GraphQL(已有 token) +- 证据协议:evidence: runs +- 本轮允许改动:src/content.config.ts、src/components/{PostList,ArtalkComments}.astro、src/components/pages/{HomePage,MomentsPage,BooksPage}.astro、src/components/geek/{ViewMeta,GithubProfile}.astro(新)、src/pages/archives/[...slug].astro、src/pages/en/archives/[...slug].astro、src/pages/{about,opensource,en/about,en/opensource}.astro、src/lib/{projects,site-content,heatmap}.ts、content/site/{about,opensource}.yaml、content/posts/*(新增示例文章)、content/posts-en/*、public/admin/{config.yml,typography-classes.js}、docs/*、tests/e2e.mjs +- 本轮不应触碰:nginx/ESA、灯箱与图库(GalleryPage/PhotoZoom)、Header/Footer 结构、构建链顺序、tokens.css/global.css 基础尺度 +- Git integration branch:`spec/2026-11-02_blog-5h-content-social` + +### 5.1 验证策略 +- 范围级别:package +- 变更对象:内容模型(置顶/瞬间富文本)、渲染组件(计数/评论/档案卡)、后台配置、示例内容 +- 快速检查:`pnpm astro build`(node26)+ `python3 scripts/build-perf/config-check.py .` +- 集成检查:`E2E_BASE=http://127.0.0.1:18925 node tests/e2e.mjs`(37 项,本包新增置顶顺序/徽标存在/瞬间富文本断言)+ content-lint 0/0/0 +- 全项目检查:生产实测四条(锁屏外链零依赖、瞬间评论可发可见、徽标数值与 Artalk 后台一致、关于页承接内容渲染) +- 升级触发:若动到 BaseLayout/全局样式或 Artalk 主题接管层,升级为全站视觉复核(glm-5.3-flash:max,≤6 图/轮) + +## 6. 成功标准与验证方式 +- [ ] 置顶文章排在列表首位且带可见标记,取消置顶后恢复时间序 -> verify: task_0001 +- [ ] 瞬间文字可用字体类与彩色强调,危险标签被净化丢弃,旧纯文本渲染不变 -> verify: task_0002 +- [ ] 每条瞬间可展开评论区并成功发帖,双语页共用同一评论流 -> verify: task_0003 +- [ ] 文章/瞬间/关于/开源四页显示「浏览数 + 评论数」徽标且数值与 Artalk 一致 -> verify: task_0004 +- [ ] 开源页零第三方图片请求,档案卡数据来自本地/GraphQL,居中与破图问题不再出现 -> verify: task_0005 +- [ ] README 的个人叙述出现在关于页,开源页只保留开源相关内容 -> verify: task_0006 +- [ ] 示例文章渲染全部演示能力且构建通过,docs/hint 同步 -> verify: task_0007 + +## 7. 风险与约束 +- 灰阶外壳红线不变:徽标图标与数字用 tokens(`--ink-*`/`--line`),不引入第三方彩色徽章 +- 彩色仅正文强调(≤3 处/页)——示例文章本身要守纪律,成为正面样本而非反例 +- 瞬间富文本必须复用 `renderRich` 净化链,禁止新增 set:html 直通路径 +- Artalk 多实例风险:评论区折叠 + 展开挂载,若实测冲突则退回「逐条跳转到锚点页」 +- 双语链路:所有新文案走 `t()`/`pickBi`,en 轨不得出现中文硬编码 +- 多车道并行:content.config.ts / public/admin/config.yml 由 orchestrator 先落契约再放行,车道只改各自 boundary 内文件 diff --git a/.spec/specs/2026-11-02_blog-5h-content-social/tasks.md b/.spec/specs/2026-11-02_blog-5h-content-social/tasks.md new file mode 100644 index 0000000..5653736 --- /dev/null +++ b/.spec/specs/2026-11-02_blog-5h-content-social/tasks.md @@ -0,0 +1,44 @@ +# Phase 5h:内容表达能力与社交反馈 - 任务拆解 + +## 使用规则 +- boundary/verify 齐备;verify 只读断言;车道工作树开发禁 git,收编由 orchestrator 统一提交 +- 构建一律 `export PATH="$HOME/.local/node/bin:$PATH"`(Node 26)+ `pnpm astro build` +- **契约先行**:`src/content.config.ts` 与 `public/admin/config.yml` 由 orchestrator 先落契约(T1 时一并提交),车道不得再改这两个文件;需要新字段一律回报 orchestrator +- E2E 口径:`pnpm astro build → cp -a dist /tmp/dist-e2e → 用 18925 端口起快照服务 → E2E_BASE=http://127.0.0.1:18925 node tests/e2e.mjs` + +## 阶段一:实现 + +- [ ] T1 文章置顶(契约 + 排序 + 标记 + 后台) + - claim: orchestrator + - boundary: src/content.config.ts(postsSchema 加 `pinned: z.boolean().optional()`,posts/postsEn 共用)、src/components/PostList.astro(置顶优先排序 + pin 标记)、src/pages/archives/index.astro(排序)、src/components/pages/{HomePage,BooksPage}.astro(排序)、public/admin/config.yml(posts 集合 pinned 开关 + 中文 hint)、src/i18n/ui.ts(置顶标签) + - verify: `E2E_BASE=http://127.0.0.1:18925 node tests/e2e.mjs 2>&1 | grep -q "37/37 PASS" && grep -q "pinned" src/content.config.ts && grep -q "pinned" src/components/PostList.astro && grep -q "pinned" public/admin/config.yml` + +- [ ] T2 瞬间富文本(字体可换 / 颜色可换 / 多形式) + - claim: worker-one + - boundary: src/components/pages/MomentsPage.astro(`text` 由纯文本 `

` 改为走 `renderRich` 净化+排版类管线,保留 inline 语义;空文本老数据零回归)、public/admin/config.yml 中 moments 集合 `text` 字段改 markdown widget + 提示可用排版类(**仅在 orchestrator 提交的字段块内改 widget 类型,不改结构**)、docs 提示留给 T7 + - verify: `E2E_BASE=http://127.0.0.1:18925 node tests/e2e.mjs 2>&1 | grep -q "37/37 PASS" && grep -qE "renderRich|renderMarkdown" src/components/pages/MomentsPage.astro && python3 -c "import yaml;d=yaml.safe_load(open('public/admin/config.yml'));m=[c for c in d['collections'] if c['name']=='moments'][0];t=[f for f in m['fields'] if f['name']=='text'][0];assert t['widget']=='markdown',t"` + +- [ ] T3 瞬间逐条评论(Artalk 独立 page_key + 折叠懒挂载) + - claim: worker-one + - boundary: 新增 src/components/MomentComments.astro(折叠 disclosure,展开时首次挂载 Artalk;page_key 约定 `/moments/#`,en 页同一 key 不分裂;评论数徽标复用 T4 的 ViewMeta 计数接口)、src/components/pages/MomentsPage.astro(每条卡片挂评论区) + - verify: `test -f src/components/MomentComments.astro && grep -q "MomentComments" src/components/pages/MomentsPage.astro && grep -q "moments/#" src/components/MomentComments.astro && E2E_BASE=http://127.0.0.1:18925 node tests/e2e.mjs 2>&1 | grep -q "37/37 PASS"` + +- [ ] T4 计数徽标(眼睛图标 = 浏览数,气泡图标 = 评论数) + - claim: op-artalk + - boundary: src/components/geek/ViewMeta.astro(**契约组件,由 orchestrator 在 T1 提交时一并落盘**,车道只消费不改语义)、src/components/ArtalkComments.astro(pv 小字行改为 ViewMeta,评论数取 `comments?limit=1` 的 count)、src/pages/archives/[...slug].astro、src/pages/en/archives/[...slug].astro(挂 ViewMeta) + - verify: `test -f src/components/geek/ViewMeta.astro && grep -q "ViewMeta" src/components/ArtalkComments.astro && grep -q "ViewMeta" src/pages/archives/[...slug].astro && E2E_BASE=http://127.0.0.1:18925 node tests/e2e.mjs 2>&1 | grep -q "37/37 PASS"` + +- [ ] T5 开源页重构(原生 GitHub 档案卡,去外链图依赖) + - claim: op-gitea + - boundary: 新增 src/components/geek/GithubProfile.astro(头像/名字/简介/关注者/总星标/语言占比,数据来自 projects.ts 与 GraphQL;零第三方图片与徽章)、src/lib/projects.ts(补统计聚合:followers/stars/language 汇总,失败降级不炸构建)、src/pages/opensource.astro、src/pages/en/opensource.astro(用 GithubProfile 替换 readme 渲染段;README 通道保留开关但默认 off 且标注不推荐)、content/site/opensource.yaml(注释说明 intro_from 现状) + - verify: `grep -q "GithubProfile" src/pages/opensource.astro && python3 -c "import re,pathlib;p=pathlib.Path('dist/opensource/index.html').read_text();bad=[u for u in ['img.shields.io','readme-typing-svg','github-readme-stats','streak-stats','komarev','github-readme-activity-graph'] if u in p];assert not bad,bad"` + +- [ ] T6 关于页承接 README 的个人叙述 + - claim: op-gitea + - boundary: content/site/about.yaml(新增 blocks:关于/兴趣 prose、站点与项目 linklist、Find Me 社交块;双语 zh/en;测试值不得留在文件里)、src/pages/about.astro 与 en(仅当块渲染需要时改,优先零改动) + - verify: `python3 -c "import yaml;d=yaml.safe_load(open('content/site/about.yaml'));types=[b['type'] for b in d.get('blocks') or []];assert 'prose' in types and ('linklist' in types or 'cards' in types),types" && E2E_BASE=http://127.0.0.1:18925 node tests/e2e.mjs 2>&1 | grep -q "37/37 PASS"` + +- [ ] T7 写作模板示例文章 + 文档与 hint 收尾 + - claim: orchestrator + - boundary: content/posts/writing-template.md、content/posts-en/writing-template.md(en 手写 locked:true 直译,不交给 TMT 重译)、docs/写作指南.md(模板用法 + 排版类清单去重指引)、docs/管理台.md(瞬间富文本/逐条评论/置顶/徽标说明)、public/admin/config.yml(moments text hint、posts pinned 已含) + - verify: `test -f content/posts/writing-template.md && test -f content/posts-en/writing-template.md && grep -q "pinned: true" content/posts/writing-template.md && grep -qE "font-kai|c-blue" content/posts/writing-template.md && grep -q "写作模板" docs/写作指南.md` diff --git a/public/admin/config.yml b/public/admin/config.yml index ccaabfa..0d7156d 100644 --- a/public/admin/config.yml +++ b/public/admin/config.yml @@ -38,6 +38,7 @@ collections: - { label: 日期, name: pubDate, widget: datetime, date_format: 'YYYY-MM-DD', time_format: false, format: 'YYYY-MM-DD' } - { label: 分轨, name: category, widget: select, options: [{label: 阅读, value: reading}, {label: 技术, value: tech}, {label: 照片, value: photo}] } - { label: 标签, name: tags, widget: list, required: false } + - { label: 置顶, name: pinned, widget: boolean, required: false, default: false, hint: '置顶文章排在首页/归档/书架最前;只影响顺序,不改日期、URL 与 RSS 时间语义' } - { label: 情绪色(书评色脊), name: mood, widget: color, required: false, hint: '#RRGGBB,仅阅读轨使用' } - { label: 原书作者, name: bookAuthor, widget: string, required: false } - { label: 一句话描述(书架策展语), name: description, widget: text, required: false } diff --git a/src/components/PostList.astro b/src/components/PostList.astro index ca23a24..50f39f6 100644 --- a/src/components/PostList.astro +++ b/src/components/PostList.astro @@ -89,6 +89,9 @@ const byMonth = (list: CollectionEntry<'posts'>[]) => { /> )} {titleOverrides?.[post.id] ?? post.data.title} + {post.data.pinned && ( + {t('pinned_label', locale)} + )} {key !== 'reading' && post.data.tags.map((tag) => {`#${tag}`})}

+ {showPv && ( + + + – + + )} + {showComments && ( + + + – + + )} +

+ + + + diff --git a/src/components/pages/BooksPage.astro b/src/components/pages/BooksPage.astro index f8348b4..eb77ced 100644 --- a/src/components/pages/BooksPage.astro +++ b/src/components/pages/BooksPage.astro @@ -5,13 +5,15 @@ import { getCollection } from 'astro:content'; import BaseLayout from '../../layouts/BaseLayout.astro'; import { t } from '../../i18n/ui'; import type { Locale } from '../../lib/locale'; +import { sortPosts } from '../../lib/post-order'; import { Image } from 'astro:assets'; interface Props { locale?: Locale } 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()); +const books = sortPosts( + await getCollection('posts', ({ data }) => !data.draft && data.category === 'reading' && !data.tags.includes('hidden')), +); // 回退契约(schema 注释声称而此前未实现——视觉复核抓到的缺口): // description 缺省取正文第一个非空段落(去 markdown 记号)前 60 字 diff --git a/src/components/pages/HomePage.astro b/src/components/pages/HomePage.astro index aad9192..b801f94 100644 --- a/src/components/pages/HomePage.astro +++ b/src/components/pages/HomePage.astro @@ -10,6 +10,7 @@ import ProjectWall from '../geek/ProjectWall.astro'; import Heatmap from '../geek/Heatmap.astro'; import SocialLinks from '../SocialLinks.astro'; import { t } from '../../i18n/ui'; +import { sortPosts } from '../../lib/post-order'; import type { Locale } from '../../lib/locale'; import { homeConfig, @@ -30,9 +31,10 @@ const cfg = await homeConfig(locale); const subtitleHtml = cfg.subtitle ? await renderMarkdown(cfg.subtitle) : ''; const announcementHtml = cfg.announcement ? await renderRich(cfg.announcement) : ''; -const posts = ( - await getCollection('posts', ({ data }) => !data.draft && !data.tags.includes('hidden')) -).sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime()); +// 置顶优先 → 时间倒序(sortPosts 契约见 src/lib/post-order.ts) +const posts = sortPosts( + await getCollection('posts', ({ data }) => !data.draft && !data.tags.includes('hidden')), +); // en 轨列表标题吃 postsEn 译题(缺译回退 zh,与 /en/archives 同策略) const enTitle = locale === 'en' diff --git a/src/content.config.ts b/src/content.config.ts index 86b843f..255be34 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -123,6 +123,8 @@ const postsSchema = z.object({ video: z.string().optional(), /** 视频封面(可选):同 public/media 下的图片 URL */ poster: z.string().optional(), + /** 置顶:列表排序优先(只影响顺序,不改 pubDate/URL/RSS 时间语义) */ + pinned: z.boolean().optional(), draft: z.boolean().optional(), }); diff --git a/src/i18n/ui.ts b/src/i18n/ui.ts index 42bbdbc..7cd1675 100644 --- a/src/i18n/ui.ts +++ b/src/i18n/ui.ts @@ -112,6 +112,9 @@ const dict = { // ===== F 车道:访问量小字(Artalk pv,组件内独立计数) ===== pv_viewed: { zh: '人看过', en: 'views' }, + pinned_label: { zh: '置顶', en: 'Pinned' }, + comment_count: { zh: '条评论', en: 'comments' }, + moment_comments: { zh: '评论', en: 'Comments' }, lb_hint: { zh: '滚轮缩放 · 双击放大 · Esc 关闭', en: 'Wheel to zoom · Double-click · Esc' }, lb_hint_touch: { zh: '双指缩放 · 双击放大', en: 'Pinch to zoom · Double-tap' }, diff --git a/src/lib/post-order.ts b/src/lib/post-order.ts new file mode 100644 index 0000000..9faa1a9 --- /dev/null +++ b/src/lib/post-order.ts @@ -0,0 +1,31 @@ +/** + * 文章列表排序契约(置顶功能,Phase 5h T1) + * + * 为什么集中在这里:首页双轨 / 归档折叠 / 书架 / en 归档四处列表各自写 + * `sort((a,b)=>b.pubDate-a.pubDate)`,加置顶必须四处同步,否则同一篇文章 + * 在不同页面位置不一致。排序键固定为「置顶优先 → 时间倒序」,时间相等时 + * 用 id 兜底保证构建确定(同一份内容两次构建产出一致,便于快照比对)。 + * + * 置顶语义:`pinned: true` 只影响列表展示顺序,不改 pubDate、不改 URL、 + * 不影响 RSS/订阅源的时间语义。 + */ +import type { CollectionEntry } from 'astro:content'; + +type SortablePost = { id: string; data: { pubDate: Date; pinned?: boolean } }; + +/** + * 置顶优先、其次按发布日期倒序。 + * + * @param posts 任意文章条目数组(不修改入参,返回新数组) + * @returns 新数组;`pinned` 为真者在前,其内部与其余条目均按 pubDate 倒序, + * 同日按 id 升序保证确定性 + */ +export function sortPosts(posts: T[]): T[] { + return [...posts].sort((a, b) => { + const pin = Number(b.data.pinned === true) - Number(a.data.pinned === true); + if (pin !== 0) return pin; + const dt = b.data.pubDate.getTime() - a.data.pubDate.getTime(); + if (dt !== 0) return dt; + return a.id < b.id ? -1 : a.id > b.id ? 1 : 0; + }); +} diff --git a/src/pages/archives/index.astro b/src/pages/archives/index.astro index 80592a3..1b0fdb1 100644 --- a/src/pages/archives/index.astro +++ b/src/pages/archives/index.astro @@ -3,9 +3,11 @@ import { getCollection } from 'astro:content'; import BaseLayout from '../../layouts/BaseLayout.astro'; import PostList from '../../components/PostList.astro'; +import { sortPosts } from '../../lib/post-order'; -const posts = (await getCollection('posts', ({ data }) => !data.draft && !data.tags.includes('hidden'))).sort( - (a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime(), +// 置顶优先 → 时间倒序(sortPosts 契约见 src/lib/post-order.ts) +const posts = sortPosts( + await getCollection('posts', ({ data }) => !data.draft && !data.tags.includes('hidden')), ); --- diff --git a/src/pages/en/archives/index.astro b/src/pages/en/archives/index.astro index 8dea9a2..2ebf30b 100644 --- a/src/pages/en/archives/index.astro +++ b/src/pages/en/archives/index.astro @@ -3,9 +3,10 @@ import { getCollection } from 'astro:content'; import BaseLayout from '../../../layouts/BaseLayout.astro'; import PostList from '../../../components/PostList.astro'; +import { sortPosts } from '../../../lib/post-order'; -const posts = (await getCollection('posts', ({ data }) => !data.draft && !data.tags.includes('hidden'))).sort( - (a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime(), +const posts = sortPosts( + await getCollection('posts', ({ data }) => !data.draft && !data.tags.includes('hidden')), ); const enTitle = Object.fromEntries( (await getCollection('postsEn')).map((e) => [e.id, e.data.title]), From 5bf0c327bf0cedb4f52f09721a6efd8de3f5760a Mon Sep 17 00:00:00 2001 From: wait4xx Date: Mon, 2 Nov 2026 20:08:21 +0800 Subject: [PATCH 02/11] =?UTF-8?q?feat(content):=20=E5=86=99=E4=BD=9C?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=A4=BA=E4=BE=8B=E6=96=87=E7=AB=A0=E4=B8=8E?= =?UTF-8?q?=E6=96=87=E6=A1=A3=EF=BC=885h=20T7=20=E4=B8=BB=E4=BD=93?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户要「在文章中加一篇关于文章书写的模板示例」,故交付一篇**可复制**的模板 文章而非干条文:正文每节都在真跑一种能力,读者看到的效果就是源码的效果。 - content/posts/writing-template.md(zh)与 posts-en 同名 en 版(locked:true 手写直译,不交给 TMT 重译):标题层级纪律、彩色强调(一页三处限额)、 字族(楷/汇文明朝各一处 + 六族清单)、引用/列表/代码窗条/表格/图片放大/ 链接卡片/details 折叠/分隔线 - pinned: true —— 这篇文章同时是置顶功能的活样本(归档首条实测) - 后台 moments.text 由 text widget 改 markdown widget + 排版类提示:瞬间从此 与文章同级表达力(字体/颜色/多段),提示里写明外壳灰阶纪律 - docs/写作指南.md 新增三节:写作模板(cp 起步 + 三条纪律)、置顶文章 (语义边界:只改顺序不改 pubDate/URL/RSS)、瞬间怎么写(富文本 + 逐条评论 + 只读计数 + text/image 至少一项) 验证: pnpm astro build 51 页 exit 0;content-lint 51 页 0 断链 0 缺图; 产物断言 c-blue/font-kai/font-huiwen/details/table 全部生效; dist/archives 首条 = writing-template(置顶排序生效) Spec: 2026-11-02_blog-5h-content-social (T7) Co-authored-by: GLM-5.3 --- content/posts-en/writing-template.md | 125 +++++++++++++++++++++++++++ content/posts/writing-template.md | 124 ++++++++++++++++++++++++++ docs/写作指南.md | 47 ++++++++++ public/admin/config.yml | 6 +- 4 files changed, 301 insertions(+), 1 deletion(-) create mode 100644 content/posts-en/writing-template.md create mode 100644 content/posts/writing-template.md diff --git a/content/posts-en/writing-template.md b/content/posts-en/writing-template.md new file mode 100644 index 0000000..ff4fab2 --- /dev/null +++ b/content/posts-en/writing-template.md @@ -0,0 +1,125 @@ +--- +title: "Writing template: this post is the template" +pubDate: 2026-11-02 +category: tech +tags: [writing, template] +pinned: true +locked: true +description: One post that exercises every typographic capability on the site — heading levels, colour emphasis, typefaces, quotes, code windows, tables, images, link cards, folding. Copy it to start a new post. +--- + +This is not a tutorial — it is a **template you can copy**. Every section below actually runs: what you see is what Markdown produces. To start a new post, copy this file, change the slug, and delete what you do not need. + +It is also the live sample for **pinning**: `pinned: true` in the frontmatter lifts a post to the front of the home page, the archive and the bookshelf, while its date, URL and RSS timestamps stay untouched. + +## 1. Heading levels and paragraphs + +Use `##` for a section and `###` for a subsection. **Never use `#`** — the post title comes from the frontmatter `title`, and a second level-one heading confuses both screen readers and search snippets. + +Leave a blank line between paragraphs. Inline you can use **bold**, *italic*, ~~strikethrough~~, `inline code`, and [ordinary links](https://astro.build). + +## 2. Colour emphasis: three per page at most + +The rule comes from the design baseline: the shell is greyscale, so colour exists to weight one judgement in the body — three per page, maximum. More than that and it turns loud. + +First use: state one key conclusion in blue. Then carry on normally. + +Second use: warn about a trap in red. For example, “after changing a Markdown plugin you must clear `node_modules/.astro`, or the change silently does nothing”. + +Third use: confirm a working path in green. After three, this section stays uncoloured. + +There are eight hues (blue / teal / green / yellow / orange / red / pink / purple), each with a standard and a `-soft` variant, plus four greyscale classes (`ink-muted` / `ink-warm` / `ink-cool` / `ink-faint`) for lowering tone — those do not count against the colour budget. + +## 3. Typefaces: change only what you wrap + +Body text is sans-serif by default. To give one sentence a different temperament, wrap it: + +This sentence is in Kai. Good for epigraphs, quoted lines in a review, or paragraphs that should be read slowly. + +This sentence is in Huiwen Ming. Over a long paragraph it noticeably slows reading, so use it for short lines only. + +Six families are available (`font-kai`, `font-song`, `font-hei-sys`, `font-fangsong`, `font-huiwen`, `font-kuaile`), plus an artistic heading class `font-art-kuaile`. **Mind the weight**: switching a whole page to a family makes every visitor download a CJK font, so avoid changing the body default casually. + +### A level-three heading looks like this + +One step smaller than level two, bold, with tighter spacing. Use it to split a section into topics. + +## 4. Quotes and lists + +> Block quotes are for quoting someone. An attribution can follow as italics. +> +> — an invented attribution + +Unordered list: + +- First item +- Second item, with `inline code` +- Third item, nested: + - Child one + - Child two + +Ordered lists suit steps: + +1. Copy the template +2. Change the slug and title in the frontmatter +3. Delete the sections you do not need + +## 5. Code blocks + +Blocks of four lines or more get a greyscale window bar (three dots); shorter fragments do not, so small snippets do not look like screenshots. + +```ts +// Sort contract: pinned first → newest first → id as a tie-breaker +export function sortPosts(posts: T[]): T[] { + return [...posts].sort((a, b) => { + const pin = Number(b.data.pinned === true) - Number(a.data.pinned === true); + return pin !== 0 ? pin : b.data.pubDate.getTime() - a.data.pubDate.getTime(); + }); +} +``` + +Refer to variables inline like `posts`. + +## 6. Tables + +| Capability | Syntax | Note | +| --- | --- | --- | +| Colour emphasis | `` | three per page at most | +| Typeface | `` | a whole page adds font weight | +| Image | `![alt](./assets//x.jpg)` | see the writing guide for size rules | +| Video | frontmatter `video:` | lives in public/media, ≤50MB | +| Link card | a bare URL on its own line | OG fetched at build time, falls back to a plain link | + +## 7. Images + +Reference images by relative path, stored under `content/posts/assets//`; they expand on click and vectors stay sharp: + +![Sample image: a greyscale coast](../posts/assets/media-sample/sample-photo.jpg) + +## 8. Link cards + +A bare URL on its own line becomes an OG preview card at build time; if the fetch fails it degrades to a plain link, never breaking the layout: + +https://astro.build + +## 9. Folding long content + +Long appendices, full logs and big configs can fold away with zero JavaScript, using native `details`: + +
+Open the folded example + +A folded region can hold anything — paragraphs, lists, code blocks. + +- Best for “read on demand” detail +- Not for conclusions (readers may never open it) + +
+ +## 10. Closing after the rule + +--- + +Three sentences are enough to close: what this covered, what the reader should take away, and where to go next. The template is not a demand to write ten sections — it is a promise that **the capabilities are at hand when you need to express something**. + +Next time, copy this file and delete until only your point remains. diff --git a/content/posts/writing-template.md b/content/posts/writing-template.md new file mode 100644 index 0000000..3c2167f --- /dev/null +++ b/content/posts/writing-template.md @@ -0,0 +1,124 @@ +--- +title: "写作模板:这篇文章本身就是模板" +pubDate: 2026-11-02 +category: tech +tags: [写作, 模板] +pinned: true +description: 一篇文章演示全站可用的排版能力:标题层级、彩色强调、字族、引用、代码窗、表格、图、链接卡、折叠。复制它开始写新文。 +--- + +这篇不是教程,是**可复制的模板**。下面每一节都在真跑——你看到的效果,就是 Markdown 源码能产出的效果。写新文章时,把本文件复制一份、改个 slug、删掉不需要的段落即可。 + +它同时是**置顶功能**的活样本:`frontmatter` 里的 `pinned: true` 会让它排在首页、归档与书架的最前面,而日期、URL、订阅源里的时间都不变。 + +## 一、标题层级与段落 + +正文用 `##` 作一级节标题,`###` 作二级。**不要用 `#`**——文章标题由 frontmatter 的 `title` 渲染,正文再写 `#` 会出现两个一级标题,屏幕阅读器与搜索摘要都会困惑。 + +段落之间空一行即可。行内可以**加粗**、*斜体*、~~删除线~~、`行内代码`,也可以放[普通链接](https://astro.build)。 + +## 二、彩色强调:一页不超过三处 + +纪律来自设计基线:站点外壳是灰阶的,颜色只用来给正文某一个判断加重,一页最多三处。超过就变成花哨。 + +第一处:一个关键结论用蓝色提出。 后面照常叙述。 + +第二处:需要警示的坑用红色。 比如「改完 Markdown 插件必须清 `node_modules/.astro`,否则改动静默不生效」。 + +第三处:确认可行的路径用绿色。 三处之后,本节不再上色。 + +可用色相共 8 组(blue / teal / green / yellow / orange / red / pink / purple),每组有标准与 `-soft` 两档;另有 4 个灰阶层级类(`ink-muted` / `ink-warm` / `ink-cool` / `ink-faint`)用于降调,不算彩色额度。 + +## 三、字族:换字体只作用于被包裹的文字 + +正文默认是无衬线。想给某句话换气质,用类包起来就行: + +这一句是楷体。适合题记、书评里引的原句,或者需要慢一点读的段落。 + +这一句是汇文明朝体。长段落用它会明显降低阅读速度,所以只用在短句上。 + +可用字族共 6 族(`font-kai` 楷、`font-song` 宋、`font-hei-sys` 黑、`font-fangsong` 仿宋、`font-huiwen` 汇文明朝、`font-kuaile` 快乐体),另有 `font-art-kuaile` 艺术字标题类。**注意体积**:整页换字族会让访问者下载一份中文字体,正文默认字体不要轻易改。 + +### 三级标题长这样 + +比二级小一档、加粗、上下留白更紧。用于把一节拆成几个小话题。 + +## 四、引用与列表 + +> 引用块用于摘录别人的话。署名可以换成斜体放在最后。 +> +> —— 一句虚构的署名 + +无序列表: + +- 第一项 +- 第二项,可以带 `行内代码` +- 第三项,可以嵌套: + - 子项一 + - 子项二 + +有序列表适合步骤: + +1. 复制模板 +2. 改 frontmatter 的 slug 与标题 +3. 删掉不需要的段落 + +## 五、代码块 + +四行及以上的代码块会带上灰阶窗条(三个点),短代码块不加——避免小片段看着像截图。 + +```ts +// 排序契约:置顶优先 → 时间倒序 → id 兜底 +export function sortPosts(posts: T[]): T[] { + return [...posts].sort((a, b) => { + const pin = Number(b.data.pinned === true) - Number(a.data.pinned === true); + return pin !== 0 ? pin : b.data.pubDate.getTime() - a.data.pubDate.getTime(); + }); +} +``` + +行内提到变量时用 `posts` 这种形式即可。 + +## 六、表格 + +| 能力 | 写法 | 注意 | +| --- | --- | --- | +| 彩色强调 | `` | 一页 ≤3 处 | +| 换字族 | `` | 整页换会拉字体体积 | +| 图片 | `![说明](./assets//x.jpg)` | 体积纪律见写作指南 | +| 视频 | frontmatter `video:` | 放 public/media,≤50MB | +| 链接卡片 | 裸链接单独成段 | 构建期抓 OG,失败回落普通链接 | + +## 七、图片 + +图片用相对路径引用,挂在 `content/posts/assets//` 下,点击可放大(矢量图不糊): + +![示例配图:一片灰阶海岸](./assets/media-sample/sample-photo.jpg) + +## 八、链接卡片 + +一个裸链接单独成段,构建期会抓取 OG 预览生成卡片;抓不到就退回普通链接,不会坏版: + +https://astro.build + +## 九、折叠长内容 + +长附录、完整日志、大段配置可以折叠,零 JS,原生 `details`: + +
+展开看一个被折叠的长例子 + +折叠区里可以放任何东西——段落、列表、代码块。 + +- 适合放「按需查看」的细节 +- 不适合放结论(读者可能永远不展开) + +
+ +## 十、分隔线之后收尾 + +--- + +收尾三句就够:这篇讲了什么、读者该带走什么、下一步去哪。模板不是要你写满十节,而是**在你需要表达时,能力都在手边**。 + +下一篇开始,复制本文件,删到只剩你要说的。 diff --git a/docs/写作指南.md b/docs/写作指南.md index 7b98257..6429cce 100644 --- a/docs/写作指南.md +++ b/docs/写作指南.md @@ -2,6 +2,36 @@ > 适用:`content/posts/*.md`(书评与技术轨通用)。资产目录约定 + 三种媒体的写法 + 体积纪律。 +## 写作模板(从这里开始,2026-11-02 起) + +别从空白文件起步——**复制现成的模板**: + +```bash +cp content/posts/writing-template.md content/posts/my-new-post.md +# 改 frontmatter 的 title / pubDate / tags / description,删掉不需要的段落 +``` + +模板本身是一篇真文章(线上读:`/archives/writing-template/`),每节都在跑一种能力,你看到的效果就是源码的效果:标题层级、三处彩色强调、两族字体、引用、列表、代码窗条、表格、图片放大、链接卡片、`
` 折叠、分隔线。 + +写之前只需记住三条纪律: +- **彩色 ≤3 处/页**:外壳是灰阶,颜色只用来给某个判断加重;超过就花哨 +- **整页换字族要谨慎**:会给访问者拉一份中文字体(汇文明朝整页约 420KB,已子集化) +- **折叠放细节不放结论**:`
` 里的内容可能永远没人展开 + +## 置顶文章 + +首页、归档、书架三处列表默认按日期倒序。想让某篇长期排在最前,frontmatter 加一行: + +```yaml +pinned: true +``` + +语义边界(刻意设计成这样): +- **只影响列表顺序**,不改 `pubDate`、不改 URL、不影响 RSS 的时间序列(订阅者不会看到时间错乱) +- 多篇同时置顶时,它们内部仍按日期倒序 +- 列表里会显示一个灰阶「置顶」小徽标,取消置顶后立刻回到时间序 +- 后台「文章」编辑页有「置顶」开关,不必手改 frontmatter + ## 目录约定 ``` @@ -223,6 +253,23 @@ typography: **层 3 · 艺术字体**:`font-art-kuaile`(站酷快乐体,艺术字专用类)。⚠️ **仅用于标题/短句**:艺术字字形大,CJK 切片体积高(实测用到页 +163KB),长段使用会显著抬高单页字体成本。 +## 瞬间(/moments)怎么写 + +瞬间与文章一样支持富文本,但入口在后台「瞬间」集合(`content/moments/*.md`): + +```yaml +--- +pubDate: 2026-11-02 +tags: [随手拍] +text: 今天把**置顶**做完了,顺手试了 彩色 +--- +``` + +- `text` 支持 markdown(`**加粗**`、列表、`> 引用`)与**同一套排版类**(字体/颜色),因为走的是与全站文案相同的净化管线:危险标签整棵丢弃,只放行 35 项白名单类 +- 一条瞬间 = 一行时间线卡片,**每条都带独立评论区**(展开才挂载,双语页共用同一评论流,评论不分裂) +- 每条的「浏览 / 评论」数字是只读统计(不会因为别人点开评论而虚增浏览) +- `text` 与 `image` 至少填一项;图片建议先压缩 + ## 页面块(关于页 blocks,字段速查) 关于页正文可由九个块拼成(后台拖拽排序,每块有「显示」开关)。完整操作见 [管理台](./管理台.md);这里是写内容时对照的字段表——文本字段一律 `{zh, en}`。 diff --git a/public/admin/config.yml b/public/admin/config.yml index 0d7156d..ad0c1cb 100644 --- a/public/admin/config.yml +++ b/public/admin/config.yml @@ -98,7 +98,11 @@ collections: sortable_fields: [pubDate, text] fields: - { label: 时间, name: pubDate, widget: datetime, date_format: 'YYYY-MM-DD', time_format: false, format: 'YYYY-MM-DD' } - - { label: 文字, name: text, widget: text, required: false, hint: '一句话(与图片至少填一项)' } + - label: 文字 + name: text + widget: markdown + required: false + hint: '与图片至少填一项。支持 markdown(**加粗**、列表、> 引用)与排版类 HTML,例如 彩色+楷体;装饰色仍守“外壳灰阶、彩色只作强调”的纪律' - { label: 图片, name: image, widget: image, required: false, hint: '与文字至少填一项;建议先压缩' } - label: 标签 name: tags From 8e74bead62cc1f97c675e7d6b29594e8dfa2a673 Mon Sep 17 00:00:00 2001 From: wait4xx Date: Mon, 2 Nov 2026 20:20:31 +0800 Subject: [PATCH 03/11] =?UTF-8?q?feat(moments):=20=E7=9E=AC=E9=97=B4?= =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E4=B8=8E=E9=80=90=E6=9D=A1=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=EF=BC=885h=20T2/T3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 瞬间文字从纯文本直出升级到与文章同级表达力,每条动态获得独立评论流。 T2 富文本: - text 在 frontmatter 预渲染成 momentId → html 的 Map(renderRich 是 async, 模板内不能 await),模板只此一处 set:html 且喂的是净化产物 - 走与全站文案同一条管线:markdown → 内容净化(标签/属性/协议三层白名单) → class 白名单 35 项,故 生效、 + + diff --git a/src/components/pages/MomentsPage.astro b/src/components/pages/MomentsPage.astro index 44fadd8..6247952 100644 --- a/src/components/pages/MomentsPage.astro +++ b/src/components/pages/MomentsPage.astro @@ -2,7 +2,9 @@ import { Image } from 'astro:assets'; import { getCollection } from 'astro:content'; import BaseLayout from '../../layouts/BaseLayout.astro'; +import MomentComments from '../MomentComments.astro'; import { t } from '../../i18n/ui'; +import { renderRich } from '../../lib/site-content'; import type { Locale } from '../../lib/locale'; // /en/ 侧由 T4 薄页传 locale='en';zh 路由无人传参,默认 zh 零回归 @@ -14,6 +16,16 @@ const { locale = 'zh' } = Astro.props; const moments = (await getCollection('moments')).sort( (a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime(), ); + +// 富文本预渲染(Phase 5h T2):text 走与页面文案同一条管线(markdown → 内容净化 → +// class 白名单 → 链接卡片),因此瞬间支持 **加粗**、、列表与换行。 +// 预渲染成 map 再进模板:renderRich 是 async,模板里不能 await。 +// 纯文本老数据零回归:无 markdown 的文本会得到单个

,与旧的 {text} 直出视觉等价。 +const richText = new Map(); +for (const m of moments) { + if (!m.data.text) continue; + richText.set(m.id, await renderRich(m.data.text)); +} const iso = (d: Date) => d.toISOString(); --- @@ -46,12 +58,13 @@ const iso = (d: Date) => d.toISOString(); /> )} - {m.data.text &&

{m.data.text}

} + {m.data.text &&
} {m.data.tags.length > 0 && (

{m.data.tags.map((tag) => {`#${tag}`})}

)} +
))} @@ -208,6 +221,41 @@ const iso = (d: Date) => d.toISOString(); background: var(--bg-soft); } .mom-card > p { font-size: 15px; color: var(--ink-2); } + /* 富文本正文(T2):首尾 margin 归零,避免卡片被

的默认外边距撑开; + 段间只留半档间距,列表缩进对齐正文基线。基调保持 15px / ink-2。 */ + .mom-text { + font-size: 15px; + color: var(--ink-2); + line-height: 1.7; + } + .mom-text :global(> :first-child) { margin-top: 0; } + .mom-text :global(> :last-child) { margin-bottom: 0; } + .mom-text :global(p) { margin: 0 0 var(--space-1); } + .mom-text :global(ul), + .mom-text :global(ol) { + margin: 0 0 var(--space-1); + padding-left: 1.35em; + } + .mom-text :global(li) { margin: 0; } + .mom-text :global(li + li) { margin-top: 2px; } + .mom-text :global(blockquote) { + margin: var(--space-1) 0; + padding-left: var(--space-2); + border-left: 2px solid var(--line); + color: var(--ink-3); + } + .mom-text :global(code) { + font-family: var(--font-mono); + font-size: 0.92em; + background: var(--bg); + border-radius: 4px; + padding: 1px 5px; + } + .mom-text :global(a) { + color: var(--accent); + text-decoration: underline; + text-underline-offset: 0.18em; + } .mom-fig { border-radius: 8px; overflow: hidden; From 63c9c8ad4aa8e5ae0a40443ae4985c4195291979 Mon Sep 17 00:00:00 2001 From: wait4xx Date: Mon, 2 Nov 2026 20:29:44 +0800 Subject: [PATCH 04/11] =?UTF-8?q?feat(counts):=20=E6=B5=8F=E8=A7=88/?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=BE=BD=E6=A0=87=E6=8E=A5=E5=85=A5=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E4=B8=8E=E7=9E=AC=E9=97=B4=E9=A1=B5=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=90=8C=E8=BD=BD=E5=8F=8C=E8=AE=A1=EF=BC=885h=20T4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户要「加一个访客数量、评论数量,采用类似于开源页面从 GitHub 移植过来的那个 眼睛图标」——落地为 ViewMeta 本地 SVG 徽标,无第三方图片依赖。 接入(op-artalk 车道): - 文章详情页 reading/tech 两分支各挂一枚 mode="page"(两分支互斥,同页仅一处计数) - ArtalkComments 顶部旧的纯文本 pv 行与自成一套的 bumpPv 脚本整段删除,改为 readonly chip:评论区只读展示,不再各计一次 - 瞬间页顶部整页 pv 行同样改 chip;每条瞬间卡片底部为 readonly 徽标 组件修复(本人,op-artalk 实测揪出): - **同载双计**:脚本既注册 astro:page-load 又立即调用 run(),首屏两者都会触发 → 每元素 POST 两次、浏览量翻倍(实测 15→17→19 每载 +2)。加每元素一次性 守卫后 1/2/3 每载 +1;软导航新元素仍照常计数 - **同页两枚数字差 1**:readonly 实例独立 GET 到的 pv 可能比计过数的少 1; 改为同键存在 page 实例时 readonly 让位,由 page 实例回填同一份结果 - page 实例请求失败时释放兄弟自读,避免评论区永远停在「–」 验证: 构建 exit 0;E2E 37/37;Playwright 拦截对账—— 每载 POST=1、同页两枚徽标文本一致(101/101)、刷新后累计 2、 接口全挂时两枚均显示占位「–」不报错 Spec: 2026-11-02_blog-5h-content-social (T4) Co-authored-by: GLM-5.3 --- .../tasks.md | 2 +- src/components/ArtalkComments.astro | 39 +++---------------- src/components/geek/ViewMeta.astro | 33 +++++++++++++++- src/components/pages/MomentsPage.astro | 36 +++-------------- src/pages/archives/[...slug].astro | 5 +++ src/pages/en/archives/[...slug].astro | 4 ++ 6 files changed, 52 insertions(+), 67 deletions(-) diff --git a/.spec/specs/2026-11-02_blog-5h-content-social/tasks.md b/.spec/specs/2026-11-02_blog-5h-content-social/tasks.md index ef36f6d..d31a50c 100644 --- a/.spec/specs/2026-11-02_blog-5h-content-social/tasks.md +++ b/.spec/specs/2026-11-02_blog-5h-content-social/tasks.md @@ -23,7 +23,7 @@ - boundary: 新增 src/components/MomentComments.astro(折叠 disclosure,展开时首次挂载 Artalk;page_key 约定 `/moments/#`,en 页同一 key 不分裂;评论数徽标复用 T4 的 ViewMeta 计数接口)、src/components/pages/MomentsPage.astro(每条卡片挂评论区) - verify: `test -f src/components/MomentComments.astro && grep -q "MomentComments" src/components/pages/MomentsPage.astro && grep -q "moments/#" src/components/MomentComments.astro && E2E_BASE=http://127.0.0.1:18925 node tests/e2e.mjs 2>&1 | grep -q "37/37 PASS"` -- [ ] T4 计数徽标(眼睛图标 = 浏览数,气泡图标 = 评论数) +- [x] T4 计数徽标(眼睛图标 = 浏览数,气泡图标 = 评论数) - claim: op-artalk - boundary: src/components/geek/ViewMeta.astro(**契约组件,由 orchestrator 在 T1 提交时一并落盘**,车道只消费不改语义)、src/components/ArtalkComments.astro(pv 小字行改为 ViewMeta,评论数取 `comments?limit=1` 的 count)、src/pages/archives/[...slug].astro、src/pages/en/archives/[...slug].astro(挂 ViewMeta) - verify: `test -f src/components/geek/ViewMeta.astro && grep -q "ViewMeta" src/components/ArtalkComments.astro && grep -q "ViewMeta" src/pages/archives/[...slug].astro && E2E_BASE=http://127.0.0.1:18925 node tests/e2e.mjs 2>&1 | grep -q "37/37 PASS"` diff --git a/src/components/ArtalkComments.astro b/src/components/ArtalkComments.astro index af5362f..463b8ba 100644 --- a/src/components/ArtalkComments.astro +++ b/src/components/ArtalkComments.astro @@ -7,15 +7,14 @@ interface Props { } const { pageKey, pageTitle } = Astro.props; import { t } from '../i18n/ui'; +import ViewMeta from './geek/ViewMeta.astro'; import { localeOf } from '../lib/locale'; const locale = localeOf(Astro.url.pathname); --- - -

- – - {' '}{t('pv_viewed', locale)} -

+ +