From f100d259d2ffebe61fef56ea3964f6d534d598c8 Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Thu, 3 Jul 2025 13:46:07 +0300 Subject: Initial pleroma pull support --- src/utils/date.ts | 4 ++-- src/utils/micro.ts | 26 ++++++++++++++++++++++++++ src/utils/webmentions.ts | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/utils/micro.ts (limited to 'src/utils') 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 { + 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; -- cgit v1.2.3