|
|
|
@ -191,6 +191,7 @@ export function createNoteLink(identifier: string): string { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Process Nostr identifiers in text |
|
|
|
* Process Nostr identifiers in text |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
// AI-NOTE: 2025-01-24 - Enhanced URL detection to prevent processing nostr identifiers that are part of URLs
|
|
|
|
export async function processNostrIdentifiers( |
|
|
|
export async function processNostrIdentifiers( |
|
|
|
content: string, |
|
|
|
content: string, |
|
|
|
ndk: NDK, |
|
|
|
ndk: NDK, |
|
|
|
@ -201,7 +202,25 @@ export async function processNostrIdentifiers( |
|
|
|
function isPartOfUrl(text: string, index: number): boolean { |
|
|
|
function isPartOfUrl(text: string, index: number): boolean { |
|
|
|
// Look for http(s):// or www. before the match
|
|
|
|
// Look for http(s):// or www. before the match
|
|
|
|
const before = text.slice(Math.max(0, index - 12), index); |
|
|
|
const before = text.slice(Math.max(0, index - 12), index); |
|
|
|
return /https?:\/\/$|www\.$/i.test(before); |
|
|
|
if (/https?:\/\/$|www\.$/i.test(before)) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the match is part of a larger URL structure
|
|
|
|
|
|
|
|
// Look for common URL patterns that might contain nostr identifiers
|
|
|
|
|
|
|
|
const beforeContext = text.slice(Math.max(0, index - 50), index); |
|
|
|
|
|
|
|
const afterContext = text.slice(index, Math.min(text.length, index + 50)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if there's a URL-like structure around the match
|
|
|
|
|
|
|
|
const urlPatterns = [ |
|
|
|
|
|
|
|
/https?:\/\/[^\s]*$/i, // URL starting with http(s)://
|
|
|
|
|
|
|
|
/www\.[^\s]*$/i, // URL starting with www.
|
|
|
|
|
|
|
|
/[^\s]*\.(com|org|net|io|eu|co|me|app|dev)[^\s]*$/i, // Common TLDs
|
|
|
|
|
|
|
|
/[^\s]*\/[^\s]*$/i, // Path-like structures
|
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const combinedContext = beforeContext + afterContext; |
|
|
|
|
|
|
|
return urlPatterns.some(pattern => pattern.test(combinedContext)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Process profiles (npub and nprofile)
|
|
|
|
// Process profiles (npub and nprofile)
|
|
|
|
|