diff options
| author | MohamedBassem <me@mbassem.com> | 2025-04-07 01:21:17 +0100 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2025-04-07 01:21:17 +0100 |
| commit | af631eb2fd211839ccb681fbb2df23ec69058fbe (patch) | |
| tree | 2ec8e0ac5ae777d6a8e596a9f84266858fdac536 /apps/web/lib/importBookmarkParser.ts | |
| parent | af6774fab6502b3f49a71dea955357992e5edc77 (diff) | |
| download | karakeep-af631eb2fd211839ccb681fbb2df23ec69058fbe.tar.zst | |
fix: Do clientside import dedup and parallelize import calls
Diffstat (limited to 'apps/web/lib/importBookmarkParser.ts')
| -rw-r--r-- | apps/web/lib/importBookmarkParser.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/apps/web/lib/importBookmarkParser.ts b/apps/web/lib/importBookmarkParser.ts index 69b8a78c..0f0797d2 100644 --- a/apps/web/lib/importBookmarkParser.ts +++ b/apps/web/lib/importBookmarkParser.ts @@ -176,3 +176,41 @@ export async function parseLinkwardenBookmarkFile( })); }); } + +export function deduplicateBookmarks( + bookmarks: ParsedBookmark[], +): ParsedBookmark[] { + const deduplicatedBookmarksMap = new Map<string, ParsedBookmark>(); + const textBookmarks: ParsedBookmark[] = []; + + for (const bookmark of bookmarks) { + if (bookmark.content?.type === BookmarkTypes.LINK) { + const url = bookmark.content.url; + if (deduplicatedBookmarksMap.has(url)) { + const existing = deduplicatedBookmarksMap.get(url)!; + // Merge tags + existing.tags = [...new Set([...existing.tags, ...bookmark.tags])]; + // Keep earliest date + const existingDate = existing.addDate ?? Infinity; + const newDate = bookmark.addDate ?? Infinity; + if (newDate < existingDate) { + existing.addDate = bookmark.addDate; + } + // Append notes if both exist + if (existing.notes && bookmark.notes) { + existing.notes = `${existing.notes}\n---\n${bookmark.notes}`; + } else if (bookmark.notes) { + existing.notes = bookmark.notes; + } + // Title: keep existing one for simplicity + } else { + deduplicatedBookmarksMap.set(url, bookmark); + } + } else { + // Keep text bookmarks as they are (no URL to dedupe on) + textBookmarks.push(bookmark); + } + } + + return [...deduplicatedBookmarksMap.values(), ...textBookmarks]; +} |
