From fbb8fbdc20e7c5af4fe41cda44c865db7b8631fd Mon Sep 17 00:00:00 2001 From: Gigi Date: Mon, 6 Oct 2025 20:34:37 +0100 Subject: [PATCH] fix: handle web bookmarks with URLs in d tag and prevent crash - Extract URL from 'd' tag for kind:39701 web bookmarks - Add protocol prefix (https://) if missing from web bookmark URLs - Make classifyUrl handle undefined input gracefully - Prevent crash when web bookmarks have no content --- src/components/BookmarkItem.tsx | 11 +++++++++-- src/utils/helpers.ts | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/BookmarkItem.tsx b/src/components/BookmarkItem.tsx index a1744100..f820663a 100644 --- a/src/components/BookmarkItem.tsx +++ b/src/components/BookmarkItem.tsx @@ -24,8 +24,15 @@ export const BookmarkItem: React.FC = ({ bookmark, index, onS const short = (v: string) => `${v.slice(0, 8)}...${v.slice(-8)}` - // Extract URLs from bookmark content - const extractedUrls = extractUrlsFromContent(bookmark.content) + // For web bookmarks (kind:39701), URL is stored in the 'd' tag + const isWebBookmark = bookmark.kind === 39701 + const webBookmarkUrl = isWebBookmark ? bookmark.tags.find(t => t[0] === 'd')?.[1] : null + + // Extract URLs from bookmark content (for regular bookmarks) + // For web bookmarks, ensure URL has protocol + const extractedUrls = webBookmarkUrl + ? [webBookmarkUrl.startsWith('http') ? webBookmarkUrl : `https://${webBookmarkUrl}`] + : extractUrlsFromContent(bookmark.content) const hasUrls = extractedUrls.length > 0 const firstUrl = hasUrls ? extractedUrls[0] : null const firstUrlClassification = firstUrl ? classifyUrl(firstUrl) : null diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index aa017469..85f9a97b 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -13,7 +13,10 @@ export interface UrlClassification { buttonText: string } -export const classifyUrl = (url: string): UrlClassification => { +export const classifyUrl = (url: string | undefined): UrlClassification => { + if (!url) { + return { type: 'article', buttonText: 'READ NOW' } + } const urlLower = url.toLowerCase() // Check for YouTube