|
3 | 3 | import { blog } from "@/lib/source" |
4 | 4 | import { PathUtils } from "fumadocs-core/source" |
5 | 5 | import { BlogSidebar } from "@/components/blog/blog-sidebar" |
| 6 | +import { lastEdit } from "@/lib/api" |
6 | 7 |
|
7 | 8 | function getName(path: string) { |
8 | 9 | return PathUtils.basename(path, PathUtils.extname(path)) |
9 | 10 | } |
10 | 11 |
|
11 | 12 | export default async function Blog() { |
12 | | - const posts = [...blog.getPages()].sort( |
| 13 | + const pages = blog.getPages() |
| 14 | + |
| 15 | + const postsWithDates = await Promise.all( |
| 16 | + pages.map(async (page) => ({ |
| 17 | + page, |
| 18 | + lastEditDate: await lastEdit(page), |
| 19 | + })) |
| 20 | + ) |
| 21 | + |
| 22 | + const posts = postsWithDates.sort( |
13 | 23 | (a, b) => |
14 | | - new Date(b.data.date ?? getName(b.path)).getTime() - |
15 | | - new Date(a.data.date ?? getName(a.path)).getTime(), |
| 24 | + new Date(b.lastEditDate ?? getName(b.page.path)).getTime() - |
| 25 | + new Date(a.lastEditDate ?? getName(a.page.path)).getTime(), |
16 | 26 | ) |
17 | 27 |
|
18 | | - const serializablePosts = posts.map((p) => ({ |
19 | | - path: p.path, |
20 | | - data: { |
21 | | - title: p.data.title, |
22 | | - description: p.data.description, |
23 | | - category: p.data.category, |
24 | | - url: p.url, |
25 | | - date: |
26 | | - (typeof p.data.date === "string" ? p.data.date : p.data.date?.toISOString()) ?? undefined, |
27 | | - }, |
28 | | - })) |
| 28 | + const serializablePosts = await Promise.all( |
| 29 | + posts.map(async (p) => ({ |
| 30 | + path: p.page.path, |
| 31 | + data: { |
| 32 | + title: p.page.data.title, |
| 33 | + description: p.page.data.description, |
| 34 | + category: p.page.data.category, |
| 35 | + url: p.page.url, |
| 36 | + date: p.lastEditDate, |
| 37 | + }, |
| 38 | + })) |
| 39 | + ) |
29 | 40 |
|
30 | 41 | return ( |
31 | 42 | <> |
|
0 commit comments