Add filter for draft posts

This commit is contained in:
Sat Naing
2022-09-22 23:36:44 +06:30
parent 023f86b2f4
commit b8b7aaef7d
2 changed files with 9 additions and 6 deletions
+7 -5
View File
@@ -2,10 +2,12 @@ import type { MarkdownInstance } from "astro";
import type { Frontmatter } from "../types";
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)
);
posts
.filter(({ frontmatter }) => !frontmatter.draft)
.sort(
(a, b) =>
Math.floor(new Date(b.frontmatter.datetime).getTime() / 1000) -
Math.floor(new Date(a.frontmatter.datetime).getTime() / 1000)
);
export default getSortedPosts;