mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
debug: add debug logs to trace NIP-19 parsing and profile resolution
- Add logs to useProfileLabels hook - Add logs to useMarkdownToHTML hook - Add logs to RichContent component - Add logs to extractNostrUris function - Add error handling with fallbacks
This commit is contained in:
@@ -19,6 +19,9 @@ const RichContent: React.FC<RichContentProps> = ({
|
|||||||
content,
|
content,
|
||||||
className = 'bookmark-content'
|
className = 'bookmark-content'
|
||||||
}) => {
|
}) => {
|
||||||
|
console.log('[RichContent] Rendering, content length:', content?.length || 0)
|
||||||
|
|
||||||
|
try {
|
||||||
// Pattern to match:
|
// Pattern to match:
|
||||||
// 1. nostr: URIs (nostr:npub1..., nostr:note1..., etc.) using applesauce Tokens.nostrLink
|
// 1. nostr: URIs (nostr:npub1..., nostr:note1..., etc.) using applesauce Tokens.nostrLink
|
||||||
// 2. http(s) URLs
|
// 2. http(s) URLs
|
||||||
@@ -27,6 +30,7 @@ const RichContent: React.FC<RichContentProps> = ({
|
|||||||
const combinedPattern = new RegExp(`(${nostrPattern.source}|${urlPattern.source})`, 'gi')
|
const combinedPattern = new RegExp(`(${nostrPattern.source}|${urlPattern.source})`, 'gi')
|
||||||
|
|
||||||
const parts = content.split(combinedPattern)
|
const parts = content.split(combinedPattern)
|
||||||
|
console.log('[RichContent] Split into parts:', parts.length)
|
||||||
|
|
||||||
// Helper to check if a string is a nostr identifier (without mutating regex state)
|
// Helper to check if a string is a nostr identifier (without mutating regex state)
|
||||||
const isNostrIdentifier = (str: string): boolean => {
|
const isNostrIdentifier = (str: string): boolean => {
|
||||||
@@ -77,6 +81,10 @@ const RichContent: React.FC<RichContentProps> = ({
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[RichContent] Error rendering:', err)
|
||||||
|
return <div className={className}>Error rendering content</div>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default RichContent
|
export default RichContent
|
||||||
|
|||||||
@@ -21,8 +21,11 @@ export const useMarkdownToHTML = (
|
|||||||
const [processedMarkdown, setProcessedMarkdown] = useState<string>('')
|
const [processedMarkdown, setProcessedMarkdown] = useState<string>('')
|
||||||
const [articleTitles, setArticleTitles] = useState<Map<string, string>>(new Map())
|
const [articleTitles, setArticleTitles] = useState<Map<string, string>>(new Map())
|
||||||
|
|
||||||
|
console.log('[useMarkdownToHTML] Hook called, markdown length:', markdown?.length || 0, 'hasRelayPool:', !!relayPool)
|
||||||
|
|
||||||
// Resolve profile labels progressively as profiles load
|
// Resolve profile labels progressively as profiles load
|
||||||
const profileLabels = useProfileLabels(markdown || '')
|
const profileLabels = useProfileLabels(markdown || '')
|
||||||
|
console.log('[useMarkdownToHTML] Profile labels size:', profileLabels.size)
|
||||||
|
|
||||||
// Fetch article titles
|
// Fetch article titles
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -68,16 +71,26 @@ export const useMarkdownToHTML = (
|
|||||||
let isCancelled = false
|
let isCancelled = false
|
||||||
|
|
||||||
const processMarkdown = () => {
|
const processMarkdown = () => {
|
||||||
|
console.log('[useMarkdownToHTML] Processing markdown, length:', markdown.length)
|
||||||
|
console.log('[useMarkdownToHTML] Profile labels:', profileLabels.size, 'Article titles:', articleTitles.size)
|
||||||
|
try {
|
||||||
// Replace nostr URIs with profile labels (progressive) and article titles
|
// Replace nostr URIs with profile labels (progressive) and article titles
|
||||||
const processed = replaceNostrUrisInMarkdownWithProfileLabels(
|
const processed = replaceNostrUrisInMarkdownWithProfileLabels(
|
||||||
markdown,
|
markdown,
|
||||||
profileLabels,
|
profileLabels,
|
||||||
articleTitles
|
articleTitles
|
||||||
)
|
)
|
||||||
|
console.log('[useMarkdownToHTML] Processed markdown length:', processed.length)
|
||||||
|
|
||||||
if (isCancelled) return
|
if (isCancelled) return
|
||||||
|
|
||||||
setProcessedMarkdown(processed)
|
setProcessedMarkdown(processed)
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[useMarkdownToHTML] Error processing markdown:', err)
|
||||||
|
if (!isCancelled) {
|
||||||
|
setProcessedMarkdown(markdown) // Fallback to original
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const rafId = requestAnimationFrame(() => {
|
const rafId = requestAnimationFrame(() => {
|
||||||
if (previewRef.current && !isCancelled) {
|
if (previewRef.current && !isCancelled) {
|
||||||
|
|||||||
@@ -12,14 +12,31 @@ const { getPubkeyFromDecodeResult, encodeDecodeResult } = Helpers
|
|||||||
export function useProfileLabels(content: string): Map<string, string> {
|
export function useProfileLabels(content: string): Map<string, string> {
|
||||||
// Extract profile pointers (npub and nprofile) using applesauce helpers
|
// Extract profile pointers (npub and nprofile) using applesauce helpers
|
||||||
const profileData = useMemo(() => {
|
const profileData = useMemo(() => {
|
||||||
|
console.log('[useProfileLabels] Processing content, length:', content?.length || 0)
|
||||||
|
try {
|
||||||
const pointers = getContentPointers(content)
|
const pointers = getContentPointers(content)
|
||||||
return pointers
|
console.log('[useProfileLabels] Found pointers:', pointers.length, 'types:', pointers.map(p => p.type))
|
||||||
.filter(p => p.type === 'npub' || p.type === 'nprofile')
|
const filtered = pointers.filter(p => p.type === 'npub' || p.type === 'nprofile')
|
||||||
.map(pointer => ({
|
console.log('[useProfileLabels] Profile pointers:', filtered.length)
|
||||||
|
const result = filtered
|
||||||
|
.map(pointer => {
|
||||||
|
try {
|
||||||
|
return {
|
||||||
pubkey: getPubkeyFromDecodeResult(pointer),
|
pubkey: getPubkeyFromDecodeResult(pointer),
|
||||||
encoded: encodeDecodeResult(pointer)
|
encoded: encodeDecodeResult(pointer)
|
||||||
}))
|
}
|
||||||
.filter(p => p.pubkey)
|
} catch (err) {
|
||||||
|
console.error('[useProfileLabels] Error processing pointer:', err, pointer)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter((p): p is { pubkey: string; encoded: string } => p !== null && !!p.pubkey)
|
||||||
|
console.log('[useProfileLabels] Profile data after filtering:', result.length)
|
||||||
|
return result
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[useProfileLabels] Error extracting pointers:', err)
|
||||||
|
return []
|
||||||
|
}
|
||||||
}, [content])
|
}, [content])
|
||||||
|
|
||||||
// Fetch profiles for all found pubkeys (progressive loading)
|
// Fetch profiles for all found pubkeys (progressive loading)
|
||||||
@@ -30,15 +47,18 @@ export function useProfileLabels(content: string): Map<string, string> {
|
|||||||
// Build profile labels map that updates reactively as profiles load
|
// Build profile labels map that updates reactively as profiles load
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const labels = new Map<string, string>()
|
const labels = new Map<string, string>()
|
||||||
|
console.log('[useProfileLabels] Building labels map, profileData:', profileData.length, 'profiles:', profiles.length)
|
||||||
profileData.forEach(({ encoded }, index) => {
|
profileData.forEach(({ encoded }, index) => {
|
||||||
const profile = profiles[index]
|
const profile = profiles[index]
|
||||||
if (profile) {
|
if (profile) {
|
||||||
const displayName = profile.name || profile.display_name || profile.nip05
|
const displayName = profile.name || profile.display_name || profile.nip05
|
||||||
if (displayName) {
|
if (displayName) {
|
||||||
labels.set(encoded, `@${displayName}`)
|
labels.set(encoded, `@${displayName}`)
|
||||||
|
console.log('[useProfileLabels] Set label:', encoded, '->', displayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
console.log('[useProfileLabels] Final labels map size:', labels.size)
|
||||||
return labels
|
return labels
|
||||||
}, [profileData, profiles])
|
}, [profileData, profiles])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,24 @@ const NOSTR_URI_REGEX = Tokens.nostrLink
|
|||||||
* Extract all nostr URIs from text using applesauce helpers
|
* Extract all nostr URIs from text using applesauce helpers
|
||||||
*/
|
*/
|
||||||
export function extractNostrUris(text: string): string[] {
|
export function extractNostrUris(text: string): string[] {
|
||||||
|
console.log('[nostrUriResolver] extractNostrUris called, text length:', text?.length || 0)
|
||||||
|
try {
|
||||||
const pointers = getContentPointers(text)
|
const pointers = getContentPointers(text)
|
||||||
return pointers.map(pointer => encodeDecodeResult(pointer))
|
console.log('[nostrUriResolver] Found pointers:', pointers.length)
|
||||||
|
const result = pointers.map(pointer => {
|
||||||
|
try {
|
||||||
|
return encodeDecodeResult(pointer)
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[nostrUriResolver] Error encoding pointer:', err, pointer)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}).filter((v): v is string => v !== null)
|
||||||
|
console.log('[nostrUriResolver] Extracted URIs:', result.length)
|
||||||
|
return result
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[nostrUriResolver] Error in extractNostrUris:', err)
|
||||||
|
return []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user