Skip to content

Commit

Permalink
fix: safari 展示文章顺序错误
Browse files Browse the repository at this point in the history
  • Loading branch information
mark9804 committed Nov 27, 2024
1 parent 959ae60 commit c0da0bd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docs/.vitepress/theme/utils/usePostData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { data as usePosts } from "../loaders/posts.data";
import type { Post } from "../types/Post";
import { unique, sift } from "radash";
import dayjs from "dayjs";

export function defaultFilter(post: Post) {
return (
Expand All @@ -13,8 +14,10 @@ export function defaultFilter(post: Post) {
export const postData = {
async getAllPosts(filter?: (post: Post) => boolean) {
const posts = (await usePosts) as Post[];
const sortedPosts = posts.sort((a, b) => b.createdAt - a.createdAt);
return filter ? sortedPosts.filter(filter) : sortedPosts;
const filteredPosts = filter ? posts.filter(filter) : posts;
return filteredPosts.sort(
(a, b) => dayjs(b.createdAt).unix() - dayjs(a.createdAt).unix()
);
},

async getCreatedAt(currentPathWithoutBase: string) {
Expand Down

0 comments on commit c0da0bd

Please sign in to comment.