diff options
Diffstat (limited to 'src/utils/micro.ts')
| -rw-r--r-- | src/utils/micro.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/utils/micro.ts b/src/utils/micro.ts new file mode 100644 index 0000000..7344850 --- /dev/null +++ b/src/utils/micro.ts @@ -0,0 +1,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); + } +} |
