From d37fe581c09f7bef797e735ef953553b6903d5b3 Mon Sep 17 00:00:00 2001 From: wait4xx Date: Thu, 5 Nov 2026 19:20:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(cms):=20=E6=96=87=E7=AB=A0=E9=A1=B5?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E4=B8=8B=E8=AF=B4=E6=98=8E=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E5=8F=AF=E7=BC=96=E8=BE=91=20+=20=E6=96=87=E7=AB=A0=E6=95=B0?= =?UTF-8?q?=20{n}=20=E5=8D=A0=E4=BD=8D=E7=AC=A6=E9=9A=8F=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后台「页面文案」新增「文章页说明」(中/英 markdown,与瞬间/书架同构的 压平结构);{n} 在构建期替换为当前可见文章数。顺修默认文案错字 (月分分组→按月分组),en 文章页补齐标题与说明行(此前只有裸列表)。 验证: pnpm astro build exit 0;dist 断言「共 10 篇」动态计数与 en 侧文案;config-check 通过;E2E 61/61 Spec: none (页面文案体系的小增量,随 5l/5m 后续直落) Co-authored-by: GLM-5.3 --- content/site/pages.yaml | 4 ++++ public/admin/config.yml | 7 +++++++ src/content.config.ts | 1 + src/lib/site-content.ts | 11 +++++++++-- src/pages/archives/index.astro | 5 ++++- src/pages/en/archives/index.astro | 19 +++++++++++++++++++ 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/content/site/pages.yaml b/content/site/pages.yaml index 21aad11..3ca9d9c 100644 --- a/content/site/pages.yaml +++ b/content/site/pages.yaml @@ -9,3 +9,7 @@ moments: books: note_zh: 点一行展开封面与简介 · 置顶的书默认展开 note_en: 'Tap a row for the cover and blurb · pinned books start open' + +archives: + note_zh: 按年份折叠 · 按月分组 · 共 {n} 篇 + note_en: 'Folded by year · grouped by month · {n} posts in total' diff --git a/public/admin/config.yml b/public/admin/config.yml index 8bf0b6b..6aa4420 100644 --- a/public/admin/config.yml +++ b/public/admin/config.yml @@ -170,6 +170,13 @@ collections: fields: - { label: 中文, name: note_zh, widget: markdown, required: false, hint: '一行小字;排版(字体/颜色)选中文字 → Insert ▸ 排版' } - { label: English, name: note_en, widget: markdown, required: false } + - label: 文章页说明 + name: archives + widget: object + required: false + fields: + - { label: 中文, name: note_zh, widget: markdown, required: false, hint: '一行小字;{n} 会替换为当前可见文章数(构建期);排版用 Insert ▸ 排版' } + - { label: English, name: note_en, widget: markdown, required: false } - name: home label: 主页设置 file: content/site/home.yaml diff --git a/src/content.config.ts b/src/content.config.ts index ee28dfe..5045183 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -246,6 +246,7 @@ export const collections = { schema: z.object({ moments: pageNoteSchema.optional(), books: pageNoteSchema.optional(), + archives: pageNoteSchema.optional(), }), }), siteTheme: defineCollection({ diff --git a/src/lib/site-content.ts b/src/lib/site-content.ts index d865f6e..31a035c 100644 --- a/src/lib/site-content.ts +++ b/src/lib/site-content.ts @@ -181,6 +181,10 @@ const PAGE_NOTE_DEFAULTS = { zh: '点一行展开封面与简介 · 置顶的书默认展开', en: 'Tap a row for the cover and blurb · pinned books start open', }, + archives: { + zh: '按年份折叠 · 按月分组 · 共 {n} 篇', + en: 'Folded by year · grouped by month · {n} posts in total', + }, } as const; /** @@ -191,13 +195,16 @@ const PAGE_NOTE_DEFAULTS = { * 「可选对象嵌可选对象不渲染子编辑器」的缺陷结构(#446/#654)。 */ export async function pageNote( - page: 'moments' | 'books', + page: 'moments' | 'books' | 'archives', locale: Locale, + /** 占位符替换(在 markdown 渲染前做):文章页用 {n}=可见文章数 */ + vars?: Record, ): Promise { const entry = await getEntry('sitePages', 'pages'); const data = entry?.data?.[page]; const fallback = PAGE_NOTE_DEFAULTS[page]; - const text = (locale === 'en' ? data?.note_en : data?.note_zh) || fallback[locale]; + let text = (locale === 'en' ? data?.note_en : data?.note_zh) || fallback[locale]; + if (vars) for (const [k, v] of Object.entries(vars)) text = text.replaceAll(`{${k}}`, String(v)); const html = await renderRich(text, { inline: true }); return { html, className: 'page-note' }; } diff --git a/src/pages/archives/index.astro b/src/pages/archives/index.astro index 214041e..5d9ff43 100644 --- a/src/pages/archives/index.astro +++ b/src/pages/archives/index.astro @@ -5,16 +5,19 @@ import { isVisiblePost } from '../../lib/post-visibility'; import BaseLayout from '../../layouts/BaseLayout.astro'; import PostList from '../../components/PostList.astro'; import { sortPosts } from '../../lib/post-order'; +import { pageNote } from '../../lib/site-content'; // 置顶优先 → 时间倒序(sortPosts 契约见 src/lib/post-order.ts) const posts = sortPosts( await getCollection('posts', ({ data }) => isVisiblePost(data)), ); +// 标题下说明:后台「页面文案 → 文章页说明」可改;{n} 占位符=可见文章数(构建期替换) +const note = await pageNote('archives', 'zh', { n: posts.length }); ---

文章

-

按年份折叠 · 月分分组 · 共 {posts.length} 篇

+

diff --git a/src/pages/en/archives/index.astro b/src/pages/en/archives/index.astro index 3a6b0e0..a832e51 100644 --- a/src/pages/en/archives/index.astro +++ b/src/pages/en/archives/index.astro @@ -5,6 +5,7 @@ import { isVisiblePost } from '../../../lib/post-visibility'; import BaseLayout from '../../../layouts/BaseLayout.astro'; import PostList from '../../../components/PostList.astro'; import { sortPosts } from '../../../lib/post-order'; +import { pageNote } from '../../../lib/site-content'; const posts = sortPosts( await getCollection('posts', ({ data }) => isVisiblePost(data)), @@ -12,8 +13,26 @@ const posts = sortPosts( const enTitle = Object.fromEntries( (await getCollection('postsEn')).map((e) => [e.id, e.data.title]), ); +const note = await pageNote('archives', 'en', { n: posts.length }); --- +

Posts

+

+ +