From 7dd411c43f5538ce3452aca2fe3d9f170de29fd7 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Mon, 19 May 2025 10:47:16 +0200 Subject: [PATCH] publication, wiki, and universal event viewer implemented. still buggy --- src/lib/components/util/InlineProfile.svelte | 10 +- src/lib/wiki.ts | 11 +- src/routes/events/+page.svelte | 124 ++++++++++++------- src/routes/wiki/+page.svelte | 32 ++++- 4 files changed, 119 insertions(+), 58 deletions(-) diff --git a/src/lib/components/util/InlineProfile.svelte b/src/lib/components/util/InlineProfile.svelte index 9ed9d5b..5daa74f 100644 --- a/src/lib/components/util/InlineProfile.svelte +++ b/src/lib/components/util/InlineProfile.svelte @@ -3,7 +3,7 @@ import { type NDKUserProfile } from "@nostr-dev-kit/ndk"; import { ndkInstance } from '$lib/ndk'; - let { pubkey, title = null } = $props(); + let { pubkey, name = null } = $props(); const externalProfileDestination = './events?id=' let loading = $state(true); @@ -43,11 +43,11 @@ {#if loading} - {title ?? '…'} + {name ?? '…'} {:else if anon } - {shortenNpub(npub)} + {shortenNpub(npub)} {:else if npub } - + {username ?? shortenNpub(npub)} {:else} - {title ?? pubkey} + {name ?? pubkey} {/if} \ No newline at end of file diff --git a/src/lib/wiki.ts b/src/lib/wiki.ts index 42a3142..f329590 100644 --- a/src/lib/wiki.ts +++ b/src/lib/wiki.ts @@ -132,18 +132,21 @@ export async function getWikiPageById(id: string, ndk: NDK) { let html = ''; try { const pharos = new Pharos(ndk); + console.log('Pharos instance:', pharos); pharos.parse(asciidoc); const pharosHtml = pharos.getHtml(); - html = await parseBasicmarkup(pharosHtml); - if (!html) { - console.error('getWikiPageById: Parsed HTML is empty for id:', id, 'event:', event); + console.log('AsciiDoc:', asciidoc); + console.log('Pharos HTML:', pharosHtml); + html = await parseBasicmarkup(pharosHtml ?? ''); + if (!html || html.trim() === '') { + console.error('getWikiPageById: Parsed HTML is empty for id:', id, 'event:', event, 'asciidoc:', asciidoc, 'pharosHtml:', pharosHtml); } } catch (err) { console.error('getWikiPageById: Error parsing content:', err, 'event:', event); return null; } - return { title, pubhex, eventId: event.id, summary, hashtags, html }; + return { title, pubhex, eventId: event.id, summary, hashtags, html, content: event.content }; } /** diff --git a/src/routes/events/+page.svelte b/src/routes/events/+page.svelte index bb1584d..b471ae3 100644 --- a/src/routes/events/+page.svelte +++ b/src/routes/events/+page.svelte @@ -78,6 +78,9 @@ error = 'Event not found'; } else { console.log('[Events] Event found:', event); + if (typeof event.getMatchingTags !== 'function') { + event = new NDKEvent(event.ndk || $ndkInstance, event); + } } } catch (err) { console.error('[Events] Error fetching event:', err, 'Query:', searchQuery); @@ -190,8 +193,7 @@ } }); - $: if (event && event.kind !== 0) { - // Only parse for non-profile events + $: if (event && event.kind !== 0 && event.content) { parseBasicmarkup(event.content).then(html => { parsedContent = html; contentPreview = html.slice(0, 250); @@ -201,6 +203,10 @@ $: profile = event && event.kind === 0 ? (() => { try { return JSON.parse(event.content); } catch { return null; } })() : null; + + $: profileTitle = event && event.kind === 0 && profile && profile.name + ? profile.name + : null;
@@ -242,7 +248,7 @@
{/if} - {#if event} + {#if event && typeof event.getMatchingTags === 'function'}
@@ -251,7 +257,11 @@
-

{getEventTitle(event)}

+ {#if event.kind !== 0 && getEventTitle(event)} +

{getEventTitle(event)}

+ {:else if event.kind === 0 && profile && profile.name} +

{profile.name}

+ {/if}
Author: @@ -283,45 +293,63 @@ Content: {#if event.kind === 0} {#if profile} -
- {#if profile.name} -
Name: {profile.name}
- {/if} - {#if profile.display_name} -
Display Name: {profile.display_name}
- {/if} - {#if profile.about} -
About: {profile.about}
- {/if} - {#if profile.picture} -
- Picture: - Profile -
- {/if} - {#if profile.banner} -
- Banner: - Banner -
- {/if} - {#if profile.website} -
- Website: - {profile.website} -
- {/if} - {#if profile.lud16} -
- Lightning Address: {profile.lud16} -
- {/if} - {#if profile.nip05} -
- NIP-05: {profile.nip05} -
- {/if} - +
+
+ {#if profile.name} +
+
Name:
+
{profile.name}
+
+ {/if} + {#if profile.display_name} +
+
Display Name:
+
{profile.display_name}
+
+ {/if} + {#if profile.about} +
+
About:
+
{profile.about}
+
+ {/if} + {#if profile.picture} +
+
Picture:
+
+ Profile +
+
+ {/if} + {#if profile.banner} +
+
Banner:
+
+ Banner +
+
+ {/if} + {#if profile.website} +
+
Website:
+
+ {profile.website} +
+
+ {/if} + {#if profile.lud16} +
+
Lightning Address:
+
{profile.lud16}
+
+ {/if} + {#if profile.nip05} +
+
NIP-05:
+
{profile.nip05}
+
+ {/if} +
{:else}
{event.content}
@@ -362,6 +390,16 @@
+ {#if !getEventTitle(event) && !event.content} +
+ No title or content available for this event. +
+            {JSON.stringify(event.rawEvent(), null, 2)}
+          
+
+ {/if} + {:else if event} +
Fetched event is not a valid NDKEvent. See console for details.
{/if}
diff --git a/src/routes/wiki/+page.svelte b/src/routes/wiki/+page.svelte index 58abf1b..466de75 100644 --- a/src/routes/wiki/+page.svelte +++ b/src/routes/wiki/+page.svelte @@ -10,7 +10,8 @@ import { neventEncode } from '$lib/utils'; import { processNostrIdentifiers } from '$lib/utils/nostrUtils'; import { standardRelays, wikiKind } from '$lib/consts'; - + import Pharos from '$lib/parser'; + import { parseBasicmarkup } from '$lib/utils/markup/basicMarkupParser'; // @ts-ignore Svelte linter false positive: hashtags is used in the template let { } = $props<{ title: string; @@ -28,6 +29,7 @@ summary: string; hashtags: string[]; html: string; + content: string; }; let searchInput = $state(''); @@ -124,6 +126,7 @@ summary: pageData.summary, hashtags: pageData.hashtags, html: processedHtml, + content: pageData.content, }; wikiContent = { title: pageData.title, @@ -205,6 +208,22 @@ wikiPage = null; } }); + + (async () => { + let html = ''; + try { + const pharos = new Pharos($ndkInstance); + pharos.parse('= Test\n\nHello world'); + const pharosHtml = pharos.getHtml(); + if (!pharosHtml || pharosHtml.trim() === '') { + console.error('Pharos failed to parse AsciiDoc:', '= Test\n\nHello world'); + } + html = await parseBasicmarkup(pharosHtml ?? ''); + console.log('Test parse result:', html); + } catch (err) { + console.error('Pharos parse error:', err); + } + })();
@@ -258,14 +277,15 @@ {/if}
{#if wikiPage.html && wikiPage.html.trim().length > 0} - {#if event && typeof event.getMatchingTags === 'function'} - {@html wikiPage.html} - {:else if event} -
Fetched event is not a valid NDKEvent. See console for details.
- {/if} + {@html wikiPage.html} {:else}
No content found for this wiki page. + {#if wikiPage.content} +
+                {wikiPage.content}
+              
+ {/if}
               {JSON.stringify(wikiPage, null, 2)}