extract post-listing logic

This commit is contained in:
2026-04-05 06:40:18 -04:00
parent e0af57e5b1
commit eda7d3aa00
4 changed files with 20 additions and 12 deletions
+10
View File
@@ -0,0 +1,10 @@
import { getCollection } from 'astro:content';
export async function listPosts() {
// all posts in dev, exlucde draft posts in prod
let entries = await getCollection('posts', ({ data }) => import.meta.env.DEV || !data.draft);
// sort by date descending
entries.sort((a, b) => b.data.date.getTime() - a.data.date.getTime());
return entries;
}