mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
Create getSortedPosts util function
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
import type { MarkdownInstance } from "astro";
|
||||||
|
|
||||||
|
interface Frontmatter {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
author: string;
|
||||||
|
datetime: string;
|
||||||
|
slug: string;
|
||||||
|
featured: boolean;
|
||||||
|
tags: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const getSortedPosts = (posts: MarkdownInstance<Frontmatter>[]) =>
|
||||||
|
posts.sort(
|
||||||
|
(a, b) =>
|
||||||
|
Math.floor(new Date(b.frontmatter.datetime).getTime() / 1000) -
|
||||||
|
Math.floor(new Date(a.frontmatter.datetime).getTime() / 1000)
|
||||||
|
);
|
||||||
|
|
||||||
|
export default getSortedPosts;
|
||||||
Reference in New Issue
Block a user