blob: 73448503575b90476aca6389789ee87a9ddd8558 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import type { CollectionEntry } from "astro:content";
export type MicroEntry = CollectionEntry<"note">;
export function sortMicroEntries(entries: MicroEntry[]): MicroEntry[] {
return entries.sort((a, b) => b.data.publishDate.getTime() - a.data.publishDate.getTime());
}
export async function getAllMicroPosts(): Promise<MicroEntry[]> {
const { getCollection } = await import("astro:content");
const notes = await getCollection("note");
// Try to get micro posts if available, otherwise just use notes
try {
const microPosts = await getCollection("micro");
const allMicroPosts: (CollectionEntry<"note"> | CollectionEntry<"micro">)[] = [
...notes,
...microPosts,
];
return sortMicroEntries(allMicroPosts as MicroEntry[]);
} catch (error) {
console.warn("Micro collection not available, using notes only:", error);
return sortMicroEntries(notes);
}
}
|