Browse Source

fix bookstr links in markdownarticles

imwald
Silberengel 3 months ago
parent
commit
6e83655371
  1. 2
      package.json
  2. 36
      src/components/Bookstr/BookstrContent.tsx
  3. 9
      src/components/Note/MarkdownArticle/MarkdownArticle.tsx

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "jumble-imwald", "name": "jumble-imwald",
"version": "16.0.0", "version": "16.1.0",
"description": "A user-friendly Nostr client focused on relay feed browsing and relay discovery, forked from Jumble", "description": "A user-friendly Nostr client focused on relay feed browsing and relay discovery, forked from Jumble",
"private": true, "private": true,
"type": "module", "type": "module",

36
src/components/Bookstr/BookstrContent.tsx

@ -533,11 +533,17 @@ export function BookstrContent({ wikilink, sourceUrl, className, skipWebPreview
setSections(updatedSections) setSections(updatedSections)
// Set initial selected versions // Set initial selected versions - prioritize version from parsed wikilink
const initialVersions = new Map<number, string>() const initialVersions = new Map<number, string>()
updatedSections.forEach((section, index) => { updatedSections.forEach((section, index) => {
if (section.versions.length > 0) { // Priority: 1) version from reference (parsed wikilink), 2) parsed.versions[0], 3) section.versions[0]
initialVersions.set(index, section.versions[0]) const versionFromRef = section.reference.version?.toUpperCase()
const versionFromParsed = parsed?.versions?.[0]?.toUpperCase()
const versionFromSection = section.versions.length > 0 ? section.versions[0] : ''
const initialVersion = versionFromRef || versionFromParsed || versionFromSection
if (initialVersion) {
initialVersions.set(index, initialVersion)
} }
}) })
setSelectedVersions(initialVersions) setSelectedVersions(initialVersions)
@ -816,12 +822,21 @@ export function BookstrContent({ wikilink, sourceUrl, className, skipWebPreview
return updated return updated
}) })
// Update selected versions // Update selected versions - prioritize version from parsed wikilink
setSelectedVersions(prevVersions => { setSelectedVersions(prevVersions => {
const updated = new Map(prevVersions) const updated = new Map(prevVersions)
newSections.forEach((section, index) => { newSections.forEach((section, index) => {
if (section.versions.length > 0 && !updated.has(index)) { // Only set if not already set (preserve user selection)
updated.set(index, section.versions[0]) if (!updated.has(index)) {
// Priority: 1) version from reference (parsed wikilink), 2) parsed.versions[0], 3) section.versions[0]
const versionFromRef = section.reference.version?.toUpperCase()
const versionFromParsed = parsed?.versions?.[0]?.toUpperCase()
const versionFromSection = section.versions.length > 0 ? section.versions[0] : ''
const initialVersion = versionFromRef || versionFromParsed || versionFromSection
if (initialVersion) {
updated.set(index, initialVersion)
}
} }
}) })
return updated return updated
@ -898,7 +913,10 @@ export function BookstrContent({ wikilink, sourceUrl, className, skipWebPreview
<div className={cn('my-2', className)}> <div className={cn('my-2', className)}>
<div className="border rounded-lg bg-muted/30 overflow-hidden"> <div className="border rounded-lg bg-muted/30 overflow-hidden">
{sections.map((section, sectionIndex) => { {sections.map((section, sectionIndex) => {
const selectedVersion = selectedVersions.get(sectionIndex) || section.versions[0] || '' // Priority for selected version: 1) user-selected, 2) version from reference, 3) parsed.versions[0], 4) section.versions[0]
const versionFromRef = section.reference.version?.toUpperCase()
const versionFromParsed = parsed?.versions?.[0]?.toUpperCase()
const selectedVersion = selectedVersions.get(sectionIndex) || versionFromRef || versionFromParsed || section.versions[0] || ''
const filteredEvents = selectedVersion const filteredEvents = selectedVersion
? section.events.filter(event => { ? section.events.filter(event => {
const metadata = extractBookMetadata(event) const metadata = extractBookMetadata(event)
@ -970,7 +988,9 @@ export function BookstrContent({ wikilink, sourceUrl, className, skipWebPreview
return null return null
} }
const externalUrl = buildExternalUrl(section.reference, bookType, selectedVersion) // Priority for Bible Gateway version: 1) version from reference, 2) selectedVersion, 3) parsed.versions[0], 4) DRA (default)
const versionForUrl = versionFromRef || selectedVersion || versionFromParsed || undefined
const externalUrl = buildExternalUrl(section.reference, bookType, versionForUrl)
if (!externalUrl) return null if (!externalUrl) return null

9
src/components/Note/MarkdownArticle/MarkdownArticle.tsx

@ -1100,7 +1100,8 @@ function parseMarkdownContent(
}) })
// Wikilinks ([[link]] or [[link|display]]) - but not inside markdown links // Wikilinks ([[link]] or [[link|display]]) - but not inside markdown links
// Exclude citations ([[citation::...]]) and bookstr links ([[book::...]]) from wikilink processing // Exclude citations ([[citation::...]]) from wikilink processing
// Note: bookstr links ([[book::...]]) are included as wikilink type and handled in rendering
const wikilinkRegex = /\[\[([^\]]+)\]\]/g const wikilinkRegex = /\[\[([^\]]+)\]\]/g
const wikilinkMatches = Array.from(content.matchAll(wikilinkRegex)) const wikilinkMatches = Array.from(content.matchAll(wikilinkRegex))
wikilinkMatches.forEach(match => { wikilinkMatches.forEach(match => {
@ -1114,11 +1115,7 @@ function parseMarkdownContent(
return return
} }
// Skip bookstr links - they're handled separately // Include bookstr links as wikilink type - they'll be handled in rendering
if (linkContent.startsWith('book::')) {
return
}
// Only add if not already covered by another pattern and not in block pattern // Only add if not already covered by another pattern and not in block pattern
const isInOther = patterns.some(p => const isInOther = patterns.some(p =>
start >= p.index && start >= p.index &&

Loading…
Cancel
Save