refactor: update getSortedPosts func for blog content collections

This commit is contained in:
satnaing
2023-01-26 22:43:35 +06:30
parent e7b93c560f
commit 57bf6d77a8
+5 -6
View File
@@ -1,13 +1,12 @@
import type { MarkdownInstance } from "astro"; import type { CollectionEntry } from "astro:content";
import type { Frontmatter } from "../types";
const getSortedPosts = (posts: MarkdownInstance<Frontmatter>[]) => const getSortedPosts = (posts: CollectionEntry<"blog">[]) =>
posts posts
.filter(({ frontmatter }) => !frontmatter.draft) .filter(({ data }) => !data.draft)
.sort( .sort(
(a, b) => (a, b) =>
Math.floor(new Date(b.frontmatter.datetime).getTime() / 1000) - Math.floor(new Date(b.data.publishDatetime).getTime() / 1000) -
Math.floor(new Date(a.frontmatter.datetime).getTime() / 1000) Math.floor(new Date(a.data.publishDatetime).getTime() / 1000)
); );
export default getSortedPosts; export default getSortedPosts;