mirror of
https://github.com/karakeep-app/karakeep.git
synced 2026-02-28 18:25:55 +01:00
* 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
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
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 });
|
|
}
|