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

+

+ +