mirror of
https://github.com/dergigi/boris.git
synced 2025-12-26 02:54:29 +01:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user