Create getSortedPosts util function

This commit is contained in:
Sat Naing
2022-09-10 16:22:30 +06:30
parent bf691069a9
commit a0d850c130
+20
View File
@@ -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;