feat(bookmarks): extract URLs from content into urlReferences for each item

This commit is contained in:
Gigi
2025-10-02 22:34:06 +02:00
parent 1b41b6e823
commit 50b32a66de
2 changed files with 20 additions and 2 deletions

View File

@@ -131,4 +131,14 @@ export function dedupeBookmarksById(bookmarks: IndividualBookmark[]): Individual
return result
}
export function extractUrlsFromContent(content: string): string[] {
if (!content) return []
// Basic URL regex covering http(s) schemes
const urlRegex = /https?:\/\/[\w.-]+(?:\/[\w\-._~:/?#[\]@!$&'()*+,;=%]*)?/gi
const matches = content.match(urlRegex)
if (!matches) return []
// Normalize by trimming trailing punctuation
return Array.from(new Set(matches.map(u => u.replace(/[),.;]+$/, ''))))
}

View File

@@ -9,7 +9,8 @@ import {
isHexId,
hasNip04Decrypt,
hasNip44Decrypt,
dedupeBookmarksById
dedupeBookmarksById,
extractUrlsFromContent
} from './bookmarkHelpers'
import { Bookmark } from '../types/bookmarks'
import { collectBookmarksFromEvents } from './bookmarkProcessing.ts'
@@ -113,7 +114,14 @@ export const fetchBookmarks = async (
])
// Sort individual bookmarks by timestamp (newest first)
const sortedBookmarks = allBookmarks.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
const enriched = allBookmarks.map(b => ({
...b,
tags: b.tags || [],
content: b.content || ''
}))
const sortedBookmarks = enriched
.map(b => ({ ...b, urlReferences: extractUrlsFromContent(b.content) }))
.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
const bookmark: Bookmark = {
id: `${activeAccount.pubkey}-bookmarks`,