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
This commit is contained in:
Gigi
2025-10-06 20:34:37 +01:00
parent 1e7be50e35
commit fbb8fbdc20
2 changed files with 13 additions and 3 deletions

View File

@@ -24,8 +24,15 @@ export const BookmarkItem: React.FC<BookmarkItemProps> = ({ 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

View File

@@ -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