From 9695bba2e993b48ae333da622fa459dbaacb9349 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 31 May 2025 18:46:04 +0100 Subject: feat: Generate RSS feeds from lists (#1507) * refactor: Move bookmark utils from shared-react to shared * Expose RSS feeds for lists * Add e2e tests * Slightly improve the look of the share dialog * allow specifying a limit in the rss endpoint --- packages/api/utils/rss.ts | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 packages/api/utils/rss.ts (limited to 'packages/api/utils/rss.ts') diff --git a/packages/api/utils/rss.ts b/packages/api/utils/rss.ts new file mode 100644 index 00000000..079b3f5a --- /dev/null +++ b/packages/api/utils/rss.ts @@ -0,0 +1,54 @@ +import RSS from "rss"; + +import serverConfig from "@karakeep/shared/config"; +import { + BookmarkTypes, + ZPublicBookmark, +} from "@karakeep/shared/types/bookmarks"; +import { getAssetUrl } from "@karakeep/shared/utils/assetUtils"; + +export function toRSS( + params: { + title: string; + description?: string; + feedUrl: string; + siteUrl: string; + }, + bookmarks: ZPublicBookmark[], +) { + const feed = new RSS({ + title: params.title, + feed_url: params.feedUrl, + site_url: params.siteUrl, + description: params.description, + generator: "Karakeep", + }); + + bookmarks + .filter( + (b) => + b.content.type === BookmarkTypes.LINK || + b.content.type === BookmarkTypes.ASSET, + ) + .forEach((bookmark) => { + feed.item({ + date: bookmark.createdAt, + title: bookmark.title ?? "", + url: + bookmark.content.type === BookmarkTypes.LINK + ? bookmark.content.url + : bookmark.content.type === BookmarkTypes.ASSET + ? `${serverConfig.publicUrl}${getAssetUrl(bookmark.content.assetId)}` + : "", + guid: bookmark.id, + author: + bookmark.content.type === BookmarkTypes.LINK + ? (bookmark.content.author ?? undefined) + : undefined, + categories: bookmark.tags, + description: bookmark.description ?? "", + }); + }); + + return feed.xml({ indent: true }); +} -- cgit v1.2.3-70-g09d2