mirror of
https://github.com/dergigi/boris.git
synced 2026-02-21 06:54:41 +01:00
feat(bookmarks): extract URLs from content into urlReferences for each item
This commit is contained in:
@@ -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(/[),.;]+$/, ''))))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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`,
|
||||
|
||||
Reference in New Issue
Block a user