From 63c9c8ad4aa8e5ae0a40443ae4985c4195291979 Mon Sep 17 00:00:00 2001 From: wait4xx Date: Mon, 2 Nov 2026 20:29:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(counts):=20=E6=B5=8F=E8=A7=88/=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E5=BE=BD=E6=A0=87=E6=8E=A5=E5=85=A5=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E4=B8=8E=E7=9E=AC=E9=97=B4=E9=A1=B5=EF=BC=8C=E4=BF=AE=E5=90=8C?= =?UTF-8?q?=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)} -

+ +