mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
refactor: update getSortedPosts func for blog content collections
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user