astro-blog/src/lib/posts.ts
2026-08-10 02:37:19 +00:00

9 lines
289 B
TypeScript

import { getCollection } from 'astro:content';
import type { CollectionEntry } from 'astro:content';
export function getSortedPosts(posts: CollectionEntry<'blog'>[]) {
return [...posts].sort(
(a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime(),
);
}