Browse Source

fix asciidoc book:: cards

imwald
Silberengel 3 months ago
parent
commit
6fd3f9cc2e
  1. 23
      src/components/Bookstr/BookstrContent.tsx
  2. 2
      src/components/Note/AsciidocArticle/AsciidocArticle.tsx
  3. 27
      src/components/WebPreview/index.tsx

23
src/components/Bookstr/BookstrContent.tsx

@ -20,6 +20,7 @@ interface BookstrContentProps { @@ -20,6 +20,7 @@ interface BookstrContentProps {
wikilink: string
sourceUrl?: string
className?: string
skipWebPreview?: boolean // If true, show simple button instead of WebPreview
}
interface BookSection {
@ -213,7 +214,7 @@ function buildExternalUrl(reference: BookReference, bookType: string, version?: @@ -213,7 +214,7 @@ function buildExternalUrl(reference: BookReference, bookType: string, version?:
}
}
export function BookstrContent({ wikilink, sourceUrl, className }: BookstrContentProps) {
export function BookstrContent({ wikilink, sourceUrl, className, skipWebPreview = false }: BookstrContentProps) {
const [sections, setSections] = useState<BookSection[]>([])
const [isLoading, setIsLoading] = useState(false) // Start as false, only set to true when actually fetching
const [error, setError] = useState<string | null>(null)
@ -958,7 +959,7 @@ export function BookstrContent({ wikilink, sourceUrl, className }: BookstrConten @@ -958,7 +959,7 @@ export function BookstrContent({ wikilink, sourceUrl, className }: BookstrConten
)}
</div>
{/* OG Preview Card for bible/torah/quran external URLs */}
{/* External URL preview/button for bible/torah/quran */}
{(() => {
// Get bookType from parsed wikilink (defaults to 'bible')
const bookType = parsed?.bookType || 'bible'
@ -973,6 +974,24 @@ export function BookstrContent({ wikilink, sourceUrl, className }: BookstrConten @@ -973,6 +974,24 @@ export function BookstrContent({ wikilink, sourceUrl, className }: BookstrConten
if (!externalUrl) return null
// If skipWebPreview is true (e.g., in AsciiDoc), show simple button
if (skipWebPreview) {
return (
<div className="mb-3">
<a
href={externalUrl}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-2 px-3 py-2 text-sm bg-muted hover:bg-muted/80 rounded-md transition-colors"
>
<ExternalLink className="h-4 w-4" />
<span>View on external site</span>
</a>
</div>
)
}
// Otherwise, use WebPreview (for markdown articles)
return (
<div className="mb-3">
<WebPreview url={externalUrl} className="w-full" />

2
src/components/Note/AsciidocArticle/AsciidocArticle.tsx

@ -1102,7 +1102,7 @@ export default function AsciidocArticle({ @@ -1102,7 +1102,7 @@ export default function AsciidocArticle({
// Check if this container already has a root to avoid re-rendering
if (!reactRootsRef.current.has(container)) {
const root = createRoot(container)
root.render(<BookstrContent wikilink={wikilink} />)
root.render(<BookstrContent wikilink={wikilink} skipWebPreview={true} />)
reactRootsRef.current.set(container, root)
}
})

27
src/components/WebPreview/index.tsx

@ -58,31 +58,6 @@ function getEventTypeName(kind: number): string { @@ -58,31 +58,6 @@ function getEventTypeName(kind: number): string {
}
}
// Helper function to extract and strip markdown/asciidoc for preview
function stripMarkdown(content: string): string {
let text = content
// Remove markdown headers
text = text.replace(/^#{1,6}\s+/gm, '')
// Remove markdown bold/italic
text = text.replace(/\*\*([^*]+)\*\*/g, '$1')
text = text.replace(/\*([^*]+)\*/g, '$1')
// Remove markdown links
text = text.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
// Remove asciidoc headers
text = text.replace(/^=+\s+/gm, '')
// Remove asciidoc bold/italic
text = text.replace(/\*\*([^*]+)\*\*/g, '$1')
text = text.replace(/_([^_]+)_/g, '$1')
// Remove code blocks
text = text.replace(/```[\s\S]*?```/g, '')
text = text.replace(/`([^`]+)`/g, '$1')
// Remove HTML tags
text = text.replace(/<[^>]+>/g, '')
// Clean up whitespace
text = text.replace(/\n{3,}/g, '\n\n')
return text.trim()
}
export default function WebPreview({ url, className }: { url: string; className?: string }) {
const { autoLoadMedia } = useContentPolicy()
const { isSmallScreen } = useScreenSize()
@ -464,7 +439,7 @@ export default function WebPreview({ url, className }: { url: string; className? @@ -464,7 +439,7 @@ export default function WebPreview({ url, className }: { url: string; className?
<div className="text-xs text-muted-foreground line-clamp-2 mb-1">{eventSummary}</div>
)}
{previewEvent && previewEvent.content && (
<div className="my-2 text-sm line-clamp-6 overflow-hidden">
<div className="my-2 text-sm line-clamp-6 overflow-hidden [&_img]:hidden">
<MarkdownArticle
event={previewEvent}
className="pointer-events-none"

Loading…
Cancel
Save