From dbe22433dfbba23839214084e58b9ea5595385bd Mon Sep 17 00:00:00 2001 From: Silberengel Date: Wed, 21 May 2025 23:57:26 +0200 Subject: [PATCH] tidied up --- src/lib/components/EventDetails.svelte | 20 +----------------- src/lib/components/Preview.svelte | 5 +++-- src/lib/components/cards/ProfileHeader.svelte | 21 ++++++++++++------- .../components/util/CopyToClipboard.svelte | 6 ++++-- src/lib/components/util/QrCode.svelte | 2 +- src/lib/parser.ts | 12 +++++------ vite.config.ts | 5 +++++ 7 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/lib/components/EventDetails.svelte b/src/lib/components/EventDetails.svelte index b056b50..17c3d0c 100644 --- a/src/lib/components/EventDetails.svelte +++ b/src/lib/components/EventDetails.svelte @@ -71,7 +71,6 @@ if (event.kind === 0) { // NIP-05 const nip05 = profile?.nip05 || getMatchingTags(event, 'nip05')[0]?.[1]; - if (nip05) ids.push({ label: 'NIP-05', value: nip05 }); // npub const npub = toNpub(event.pubkey); if (npub) ids.push({ label: 'npub', value: npub, link: `/events?id=${npub}` }); @@ -155,7 +154,7 @@ {#if event.kind === 0} - + {/if} @@ -170,23 +169,6 @@ {/if} - -
- Identifiers: -
- {#each getIdentifiers(event, profile) as id} - {#if id.link} - {id.label}: {id.value} - {:else} - {id.label}: {id.value} - {/if} - {/each} -
-
-
diff --git a/src/lib/components/Preview.svelte b/src/lib/components/Preview.svelte index e7a3f29..8a33d01 100644 --- a/src/lib/components/Preview.svelte +++ b/src/lib/components/Preview.svelte @@ -5,6 +5,7 @@ import Self from './Preview.svelte'; import { contentParagraph, sectionHeading } from '$lib/snippets/PublicationSnippets.svelte'; import BlogHeader from "$components/cards/BlogHeader.svelte"; + import { getMatchingTags } from '$lib/utils/nostrUtils'; // TODO: Fix move between parents. @@ -101,14 +102,14 @@ function byline(rootId: string, index: number) { console.log(rootId, index, blogEntries); const event = blogEntries[index][1]; - const author = event ? event.getMatchingTags("author")[0][1] : ''; + const author = event ? getMatchingTags(event, 'author')[0][1] : ''; return author ?? ""; } function hasCoverImage(rootId: string, index: number) { console.log(rootId); const event = blogEntries[index][1]; - const image = event && event.getMatchingTags("image")[0] ? event.getMatchingTags("image")[0][1] : ''; + const image = event && getMatchingTags(event, 'image')[0] ? getMatchingTags(event, 'image')[0][1] : ''; return image ?? ''; } diff --git a/src/lib/components/cards/ProfileHeader.svelte b/src/lib/components/cards/ProfileHeader.svelte index bee6f48..206f994 100644 --- a/src/lib/components/cards/ProfileHeader.svelte +++ b/src/lib/components/cards/ProfileHeader.svelte @@ -5,10 +5,11 @@ import { type NostrProfile, toNpub } from "$lib/utils/nostrUtils.ts"; import QrCode from "$components/util/QrCode.svelte"; import CopyToClipboard from "$components/util/CopyToClipboard.svelte"; - import { bech32 } from 'bech32'; + // @ts-ignore + import { bech32 } from 'https://esm.sh/bech32'; import type { NDKEvent } from "@nostr-dev-kit/ndk"; - const { event, profile } = $props<{ event: NDKEvent, profile: NostrProfile }>(); + const { event, profile, identifiers = [] } = $props<{ event: NDKEvent, profile: NostrProfile, identifiers?: { label: string, value: string, link?: string }[] }>(); let lnModalOpen = $state(false); let lnurl = $state(null); @@ -71,18 +72,24 @@ {/if} + {#if profile.lud16} +
+
Lightning Address:
+
+
+ {/if} {#if profile.nip05}
NIP-05:
{profile.nip05}
{/if} - {#if profile.lud16} -
-
Lightning Address:
-
+ {#each identifiers as id} +
+
{id.label}:
+
{#if id.link}{id.value}{:else}{id.value}{/if}
- {/if} + {/each}
diff --git a/src/lib/components/util/CopyToClipboard.svelte b/src/lib/components/util/CopyToClipboard.svelte index 19c9850..600ff65 100644 --- a/src/lib/components/util/CopyToClipboard.svelte +++ b/src/lib/components/util/CopyToClipboard.svelte @@ -34,8 +34,10 @@ {#if copied} Copied! {:else} - {#if icon} - + {#if icon === ClipboardCleanOutline} + + {:else if icon === ClipboardCheckOutline} + {/if} {displayText} {/if} diff --git a/src/lib/components/util/QrCode.svelte b/src/lib/components/util/QrCode.svelte index 5e74a76..616b995 100644 --- a/src/lib/components/util/QrCode.svelte +++ b/src/lib/components/util/QrCode.svelte @@ -14,4 +14,4 @@ onMount(renderQR); - + diff --git a/src/lib/parser.ts b/src/lib/parser.ts index e9b3a4c..860a8c6 100644 --- a/src/lib/parser.ts +++ b/src/lib/parser.ts @@ -629,7 +629,7 @@ export default class Pharos { let content: string = ''; // Format title into AsciiDoc header. - const title = event.getMatchingTags('title')[0][1]; + const title = getMatchingTags(event, 'title')[0][1]; let titleLevel = ''; for (let i = 0; i <= depth; i++) { titleLevel += '='; @@ -639,7 +639,7 @@ export default class Pharos { // TODO: Deprecate `e` tags in favor of `a` tags required by NIP-62. let tags = getMatchingTags(event, 'a'); if (tags.length === 0) { - tags = event.getMatchingTags('e'); + tags = getMatchingTags(event, 'e'); } // Base case: The event is a zettel. @@ -654,10 +654,10 @@ export default class Pharos { ); // if a blog, save complete events for later - if (event.getMatchingTags("type").length > 0 && event.getMatchingTags("type")[0][1] === 'blog') { + if (getMatchingTags(event, 'type').length > 0 && getMatchingTags(event, 'type')[0][1] === 'blog') { childEvents.forEach(child => { if (child) { - this.blogEntries.set(child?.getMatchingTags("d")?.[0]?.[1], child); + this.blogEntries.set(getMatchingTags(child, 'd')?.[0]?.[1], child); } }) } @@ -666,8 +666,8 @@ export default class Pharos { if (event.created_at) { this.rootIndexMetadata.publicationDate = new Date(event.created_at * 1000).toDateString(); } - if (event.getMatchingTags('image').length > 0) { - this.rootIndexMetadata.coverImage = event.getMatchingTags('image')[0][1]; + if (getMatchingTags(event, 'image').length > 0) { + this.rootIndexMetadata.coverImage = getMatchingTags(event, 'image')[0][1]; } // Michael J - 15 December 2024 - This could be further parallelized by recursively fetching diff --git a/vite.config.ts b/vite.config.ts index fc84d3a..61e619b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -26,6 +26,11 @@ export default defineConfig({ $components: './src/components' } }, + build: { + rollupOptions: { + external: ['bech32'] + } + }, test: { include: ['./tests/unit/**/*.test.ts', './tests/integration/**/*.test.ts'] },