mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
80e67a1dca
* feat: add modified datetime in blog posts Add modDatetime in blogSchema. Update Datetime component to accept modDatetime. Update sorting logic. Rename datetime to pubDatetime in Datetime component. Closes: #134 * feat: add published_time & modified_time meta tags * docs: update related blog posts to be up-to-date * fix: remove extra spaces in breadcrumbs
18 lines
459 B
TypeScript
18 lines
459 B
TypeScript
import type { CollectionEntry } from "astro:content";
|
|
|
|
const getSortedPosts = (posts: CollectionEntry<"blog">[]) => {
|
|
return posts
|
|
.filter(({ data }) => !data.draft)
|
|
.sort(
|
|
(a, b) =>
|
|
Math.floor(
|
|
new Date(b.data.modDatetime ?? b.data.pubDatetime).getTime() / 1000
|
|
) -
|
|
Math.floor(
|
|
new Date(a.data.modDatetime ?? a.data.pubDatetime).getTime() / 1000
|
|
)
|
|
);
|
|
};
|
|
|
|
export default getSortedPosts;
|