From 58baad5a7bc7f6b86ab3d72401f5724d29154d34 Mon Sep 17 00:00:00 2001 From: wait4xx Date: Wed, 4 Nov 2026 20:14:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(content):=20=E7=9E=AC=E9=97=B4/=E4=B9=A6?= =?UTF-8?q?=E6=9E=B6=E6=A0=87=E9=A2=98=E4=B8=8B=E7=9A=84=E8=AF=9D=E8=AF=AD?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=90=8E=E5=8F=B0=E5=8F=AF=E7=BC=96=E8=BE=91?= =?UTF-8?q?=EF=BC=885j=20T3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户原话:「瞬间、书架大标题下的话语我从哪里去改?包括其字号颜色还有字体」—— 此前这两行是硬编码(瞬间来自 i18n 字典、书架是组件里的字面量),后台完全改不了。 - 新增 sitePages 单例(content/site/pages.yaml)+ pageNote() 访问器:note 走富文本 行内管线,空则回落内置默认(原硬编码两句逐字搬入 PAGE_NOTE_DEFAULTS) - 样式只开放三档并全部夹取:size 11–16px、color 仅 ink-1..ink-4、font 仅排版类白名单 —— 后台可填任意值,不能让它破版或染色 - **关键坑**:字体类不能只挂 class——global.css 的 .font-kai/.font-sans 全挂在富文本 容器作用域(.prose-*/.rich/.mom-text/.prose-body),裸 .page-note.font-kai 拿不到 规则(实测第一次无效,仍是 Noto Sans)。改为复用 fontVarFor() 产出 inline font-family,class 仅作语义 - 书架与瞬间各自独立配置;默认值取「改造前外观」(均 font-sans) 验证: 构建 exit 0;content-lint 52 页 0/0/0;E2E 56/56; 实测(只改 books 样式)书架 computed = 16px / rgb(51,52,58) / Ma Shan Zheng, 瞬间保持 13px / ink-4 / Noto Sans(两页互不影响); op-gitea 侧另测:仅改文本、整段删 style(与基线逐字段一致)、非法值 (size:40/color:red/font 乱写)全部安全回落 Spec: 2026-11-03_blog-5j-content-refine (T3) Co-authored-by: GLM-5.3 --- content/site/pages.yaml | 21 +++++++++++++++++++++ src/components/pages/BooksPage.astro | 10 +++++----- src/components/pages/MomentsPage.astro | 7 +++++-- 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 content/site/pages.yaml diff --git a/content/site/pages.yaml b/content/site/pages.yaml new file mode 100644 index 0000000..d8f2a8f --- /dev/null +++ b/content/site/pages.yaml @@ -0,0 +1,21 @@ +# 页面标题下的说明文案(瞬间 / 书架):文字、字号、颜色、字体都在这里改。 +# 缺省即回落内置默认,删字段不会破版。 +# 说明:color 取 tokens 里的灰阶层级(ink-1..ink-4);font 取排版类白名单里的字体类。 + +moments: + note: + zh: 零碎的记录:随手拍、一句话感想、开源动态。 + en: 'Fragmented notes: casual shots, one-liners, and open-source updates.' + style: + size: 13 + color: ink-4 + font: font-sans + +books: + note: + zh: 点一行展开封面与简介 · 置顶的书默认展开 + en: 'Tap a row for the cover and blurb · pinned books start open' + style: + size: 13 + color: ink-4 + font: font-sans # 与改造前一致;想用楷体改成 font-kai diff --git a/src/components/pages/BooksPage.astro b/src/components/pages/BooksPage.astro index c141edb..5d50249 100644 --- a/src/components/pages/BooksPage.astro +++ b/src/components/pages/BooksPage.astro @@ -18,11 +18,14 @@ import BaseLayout from '../../layouts/BaseLayout.astro'; import { t } from '../../i18n/ui'; import type { Locale } from '../../lib/locale'; import { sortPosts } from '../../lib/post-order'; +import { pageNote } from '../../lib/site-content'; interface Props { locale?: Locale; } const { locale = 'zh' } = Astro.props; +// 标题下说明:文字与样式都可后台改(白名单校验,非法值回落) +const note = await pageNote('books', locale); const books = sortPosts( await getCollection( @@ -58,10 +61,6 @@ const pinnedCount = items.filter((i) => i.pinned).length; const L = { shelf: t('books_title', locale), count: locale === 'zh' ? `${items.length} 本` : `${items.length} books`, - note: - locale === 'zh' - ? '点一行展开封面与简介 · 置顶的书默认展开' - : 'Tap a row for the cover and blurb · pinned books start open', read: locale === 'zh' ? '读这篇书评 →' : 'Read the review →', pinned: t('pinned_label', locale), expand: locale === 'zh' ? '展开封面与简介' : 'Expand cover and blurb', @@ -77,7 +76,8 @@ const L = { {L.shelf}{L.count} {pinnedCount > 0 && {pinnedCount} {L.pinned}} -

{L.note}

+ +