From c57469478756c89edfa5db91609b95536a4fcb4b Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Sun, 15 Dec 2024 12:59:35 -0600 Subject: [PATCH] Use Preview component for reader view --- src/lib/components/Article.svelte | 116 +++++++++++++----------------- 1 file changed, 48 insertions(+), 68 deletions(-) diff --git a/src/lib/components/Article.svelte b/src/lib/components/Article.svelte index 032865c..2935342 100644 --- a/src/lib/components/Article.svelte +++ b/src/lib/components/Article.svelte @@ -3,36 +3,24 @@ import type { NDKEvent } from '@nostr-dev-kit/ndk'; import { page } from '$app/stores'; import { Button, Heading, Sidebar, SidebarGroup, SidebarItem, SidebarWrapper, Skeleton, TextPlaceholder, Tooltip } from 'flowbite-svelte'; - import showdown from 'showdown'; import { onMount } from 'svelte'; import { BookOutline } from 'flowbite-svelte-icons'; - import { zettelKinds } from '../consts'; + import Pharos, { parser } from '$lib/parser'; + import Preview from './Preview.svelte'; export let index: NDKEvent | null | undefined; + $parser ??= new Pharos($ndk); + $: activeHash = $page.url.hash; - const getEvents = async (index?: NDKEvent | null | undefined): Promise> => { - if (index == null) { - // TODO: Add error handling. + const getContentRoot = async (index?: NDKEvent | null | undefined): Promise => { + if (!index) { + return null; } - const eventIds = index!.getMatchingTags('e').map((value) => value[1]); - const events = await $ndk.fetchEvents( - { - // @ts-ignore - kinds: zettelKinds, - ids: eventIds, - }, - { - groupable: false, - skipVerification: false, - skipValidation: false - } - ); - - console.debug(`Fetched ${events.size} events from ${eventIds.length} references.`); - return events; + await $parser.fetch(index); + return $parser.getRootIndexId(); }; function normalizeHashPath(str: string): string { @@ -104,62 +92,54 @@ window.removeEventListener('click', hideTocOnClick); }; }); - - const converter = new showdown.Converter(); -{#await getEvents(index)} +{#await getContentRoot(index)} -{:then events} - {#if showTocButton && !showToc} - - - Show Table of Contents - - {/if} - {#if showToc} - - - - {#each events as event} - - {/each} - - - +{:then rootId} + {#if rootId} + {#if showTocButton && !showToc} + + + Show Table of Contents + + {/if} + + +
+ +
+ {:else} + {/if} -
- {#each events as event} -
- - {event.getMatchingTags('title')[0][1]} - - {@html converter.makeHtml(event.content)} -
- {/each} -
{/await}