Browse Source

fix markup tags in the OG fallback cards

ressurect the book:: wikilinks
imwald
Silberengel 3 months ago
parent
commit
30a6b74740
  1. 25
      src/components/WebPreview/index.tsx

25
src/components/WebPreview/index.tsx

@ -18,6 +18,7 @@ import client from '@/services/client.service'
import { Event } from 'nostr-tools' import { Event } from 'nostr-tools'
import { BIG_RELAY_URLS } from '@/constants' import { BIG_RELAY_URLS } from '@/constants'
import { getImetaInfosFromEvent } from '@/lib/event' import { getImetaInfosFromEvent } from '@/lib/event'
import MarkdownArticle from '../Note/MarkdownArticle/MarkdownArticle'
// Helper function to get event type name // Helper function to get event type name
function getEventTypeName(kind: number): string { function getEventTypeName(kind: number): string {
@ -346,11 +347,15 @@ export default function WebPreview({ url, className }: { url: string; className?
const { profile: eventAuthorProfile } = useFetchProfile(eventAuthorProfileId) const { profile: eventAuthorProfile } = useFetchProfile(eventAuthorProfileId)
// Get content preview (first 500 chars, stripped of markdown) - ALWAYS call hooks before any returns // Create synthetic event for content preview rendering - ALWAYS call hooks before any returns
const contentPreview = useMemo(() => { const previewEvent = useMemo(() => {
if (!fetchedEvent?.content) return '' if (!fetchedEvent?.content) return null
const stripped = stripMarkdown(fetchedEvent.content) // Create a synthetic event with the content for MarkdownArticle rendering
return stripped.length > 500 ? stripped.substring(0, 500) + '...' : stripped // We'll use the full content and let CSS handle truncation
return {
...fetchedEvent,
content: fetchedEvent.content
} as Event
}, [fetchedEvent]) }, [fetchedEvent])
// Early return after ALL hooks are called // Early return after ALL hooks are called
@ -458,9 +463,13 @@ export default function WebPreview({ url, className }: { url: string; className?
{eventSummary && ( {eventSummary && (
<div className="text-xs text-muted-foreground line-clamp-2 mb-1">{eventSummary}</div> <div className="text-xs text-muted-foreground line-clamp-2 mb-1">{eventSummary}</div>
)} )}
{contentPreview && ( {previewEvent && previewEvent.content && (
<div className="my-2 text-sm whitespace-pre-wrap break-words line-clamp-6"> <div className="my-2 text-sm line-clamp-6 overflow-hidden">
{contentPreview} <MarkdownArticle
event={previewEvent}
className="pointer-events-none"
hideMetadata={true}
/>
</div> </div>
)} )}
</> </>

Loading…
Cancel
Save