Sort the post list
This commit is contained in:
parent
586ab0287b
commit
0a138a608f
@ -13,7 +13,10 @@ const app = new Hono<{ Variables: Posts }>();
|
|||||||
app.get("/", async (c) => {
|
app.get("/", async (c) => {
|
||||||
const postService: PostFileService = c.get('postService');
|
const postService: PostFileService = c.get('postService');
|
||||||
const posts = postService.getPosts();
|
const posts = postService.getPosts();
|
||||||
const postList: PostMeta[] = Array.from(posts.values()).map((p: Post) => p.meta);
|
const postList: PostMeta[] = Array.from(posts.values())
|
||||||
|
.map((p: Post) => p.meta)
|
||||||
|
.sort((p1: Post, p2: Post) => p1.meta.date - p2.meta.date);
|
||||||
|
|
||||||
|
|
||||||
return c.render(<Home posts={postList} />, {
|
return c.render(<Home posts={postList} />, {
|
||||||
meta: {
|
meta: {
|
||||||
|
@ -54,6 +54,16 @@ export class PostFileService {
|
|||||||
return this.posts;
|
return this.posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getPostsSortedByDate(desc: boolean = true): Post[] {
|
||||||
|
return Array.from(this.posts.entries()).sort((p1: Post, p2: Post) => {
|
||||||
|
if (desc) {
|
||||||
|
return p1.meta.date - p2.meta.date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return p2.meta.date - p1.meta.date;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public getPost(slug: string): Post {
|
public getPost(slug: string): Post {
|
||||||
const post = this.posts.get(slug);
|
const post = this.posts.get(slug);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user