From 0b6a5881b99027be9a175e7d1f2b112daef1ab51 Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Thu, 3 Jul 2025 14:31:38 +0300 Subject: Add images support --- src/components/note/Note.astro | 21 +++++++++++++++++++++ src/loaders/pleroma.ts | 14 ++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'src') diff --git a/src/components/note/Note.astro b/src/components/note/Note.astro index a8cf205..3017d2d 100644 --- a/src/components/note/Note.astro +++ b/src/components/note/Note.astro @@ -44,6 +44,27 @@ const { Content } = await render(note); class:list={{ "line-clamp-6": isPreview }} > + { + !isPreview && note.data.attachments && note.data.attachments.length > 0 && ( +
+ {note.data.attachments.map((attachment: { url: string; type: string }) => ( + + Attachment + + ))} +
+ ) + } { !isPreview && note.data.sourceUrl && ( <> diff --git a/src/loaders/pleroma.ts b/src/loaders/pleroma.ts index a0b169f..feb11c8 100644 --- a/src/loaders/pleroma.ts +++ b/src/loaders/pleroma.ts @@ -314,6 +314,15 @@ export function pleromaLoader(config: PleromaFeedConfig): Loader { // Extract source URL from the entry const sourceUrl = entry.link?.find(link => link["@_rel"] === "alternate")?.["@_href"] || entry.id; + // Extract image attachments + const attachments = entry.link?.filter(link => + link["@_rel"] === "enclosure" && + link["@_type"]?.startsWith("image/") + ).map(link => ({ + url: link["@_href"], + type: link["@_type"] + })) || []; + // Create note entry store.set({ id: `pleroma-${postId}`, @@ -323,6 +332,7 @@ export function pleromaLoader(config: PleromaFeedConfig): Loader { cleanedContent.substring(0, 160) + (cleanedContent.length > 160 ? "..." : ""), publishDate: new Date(entry.published), sourceUrl, + attachments, }, body: cleanedContent, rendered: { @@ -363,6 +373,9 @@ export function pleromaLoader(config: PleromaFeedConfig): Loader { // Use the link as source URL const sourceUrl = typeof item.link === "string" ? item.link : item.guid || ""; + // For RSS, attachments would be empty since we're actually getting Atom feeds + const attachments: { url: string; type: string }[] = []; + // Create note entry store.set({ id: `pleroma-${postId}`, @@ -372,6 +385,7 @@ export function pleromaLoader(config: PleromaFeedConfig): Loader { cleanedContent.substring(0, 160) + (cleanedContent.length > 160 ? "..." : ""), publishDate: new Date(item.pubDate), sourceUrl, + attachments, }, body: cleanedContent, rendered: { -- cgit v1.2.3