diff options
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/date.ts | 4 | ||||
| -rw-r--r-- | src/utils/micro.ts | 26 | ||||
| -rw-r--r-- | src/utils/webmentions.ts | 2 |
3 files changed, 29 insertions, 3 deletions
diff --git a/src/utils/date.ts b/src/utils/date.ts index fb943a5..b919810 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -16,8 +16,8 @@ export function getFormattedDate( } export function collectionDateSort( - a: CollectionEntry<"post" | "note">, - b: CollectionEntry<"post" | "note">, + a: CollectionEntry<"post" | "note" | "micro">, + b: CollectionEntry<"post" | "note" | "micro">, ) { return b.data.publishDate.getTime() - a.data.publishDate.getTime(); } 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); + } +} diff --git a/src/utils/webmentions.ts b/src/utils/webmentions.ts index c9f62b7..8edfd90 100644 --- a/src/utils/webmentions.ts +++ b/src/utils/webmentions.ts @@ -1,5 +1,5 @@ -import * as fs from "node:fs"; import { WEBMENTION_API_KEY } from "astro:env/server"; +import * as fs from "node:fs"; import type { WebmentionsCache, WebmentionsChildren, WebmentionsFeed } from "@/types"; const DOMAIN = import.meta.env.SITE; |
