feat(chronicle): sort article list newest first

List now renders newest-to-oldest; item numbers stay in chronological
order to match the 第 N 篇 numbering on article pages.
This commit is contained in:
hanyixuanten committed 2026-10-25 11:58:04 +00:00
1 parent e401569926
commit 106e4b76b2
1 file changed
+15 -13
+15 -13
View File
@@ -3,8 +3,8 @@ export const prerender = true;
import { getCollection } from "astro:content"; import { getCollection } from "astro:content";
import { SITE } from "../site.config"; import { SITE } from "../site.config";
// 班史列表:src/content/*.md(与首页「班级编年史」同源) // 班史列表:src/content/*.md
// 升序排列,序号与文章页「第 N 篇」一致 // 按时间倒序展示(最新在前);序号仍是时间正序的第 N 篇,与文章页一致
const posts = (await getCollection("chronicle")).sort( const posts = (await getCollection("chronicle")).sort(
(a, b) => a.data.date.valueOf() - b.data.date.valueOf(), (a, b) => a.data.date.valueOf() - b.data.date.valueOf(),
); );
@@ -12,17 +12,19 @@ const posts = (await getCollection("chronicle")).sort(
const pad = (n: number) => String(n).padStart(2, "0"); const pad = (n: number) => String(n).padStart(2, "0");
const total = posts.length; const total = posts.length;
const items = posts.map((post, i) => { const items = posts
const d = post.data.date; .map((post, i) => {
return { const d = post.data.date;
index: i + 1, return {
dateLabel: `${d.getFullYear()} · ${pad(d.getMonth() + 1)} · ${pad(d.getDate())}`, index: i + 1,
title: post.data.title, dateLabel: `${d.getFullYear()} · ${pad(d.getMonth() + 1)} · ${pad(d.getDate())}`,
summary: post.data.summary, title: post.data.title,
author: post.data.author, summary: post.data.summary,
url: `/pages/${post.id.split("/").pop()}`, author: post.data.author,
}; url: `/pages/${post.id.split("/").pop()}`,
}); };
})
.reverse();
--- ---
<html lang="zh-CN"> <html lang="zh-CN">