mirror of
https://github.com/Vb-Lg/class-history-template.git
synced 2026-11-03 17:36:47 +00:00
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:
1 parent
e401569926
commit
106e4b76b2
1 file changed
+6
-4
@@ -3,8 +3,8 @@ export const prerender = true;
|
||||
import { getCollection } from "astro:content";
|
||||
import { SITE } from "../site.config";
|
||||
|
||||
// 班史列表:src/content/*.md(与首页「班级编年史」同源)
|
||||
// 升序排列,序号与文章页「第 N 篇」一致
|
||||
// 班史列表:src/content/*.md
|
||||
// 按时间倒序展示(最新在前);序号仍是时间正序的第 N 篇,与文章页一致
|
||||
const posts = (await getCollection("chronicle")).sort(
|
||||
(a, b) => a.data.date.valueOf() - b.data.date.valueOf(),
|
||||
);
|
||||
@@ -12,7 +12,8 @@ const posts = (await getCollection("chronicle")).sort(
|
||||
const pad = (n: number) => String(n).padStart(2, "0");
|
||||
const total = posts.length;
|
||||
|
||||
const items = posts.map((post, i) => {
|
||||
const items = posts
|
||||
.map((post, i) => {
|
||||
const d = post.data.date;
|
||||
return {
|
||||
index: i + 1,
|
||||
@@ -22,7 +23,8 @@ const items = posts.map((post, i) => {
|
||||
author: post.data.author,
|
||||
url: `/pages/${post.id.split("/").pop()}`,
|
||||
};
|
||||
});
|
||||
})
|
||||
.reverse();
|
||||
---
|
||||
|
||||
<html lang="zh-CN">
|
||||
|
||||
Reference in new issue
Block a user