|
|
|
|
@ -12,18 +12,24 @@
@@ -12,18 +12,24 @@
|
|
|
|
|
|
|
|
|
|
let { data }: PageProps = $props(); |
|
|
|
|
|
|
|
|
|
const indexEvent = createNDKEvent(data.ndk, data.indexEvent); |
|
|
|
|
const publicationTree = new SveltePublicationTree(indexEvent, data.ndk); |
|
|
|
|
const toc = new TableOfContents( |
|
|
|
|
// data.indexEvent can be null from server-side rendering |
|
|
|
|
// We need to handle this case properly |
|
|
|
|
const indexEvent = data.indexEvent ? createNDKEvent(data.ndk, data.indexEvent) : null; |
|
|
|
|
|
|
|
|
|
// Only create publication tree if we have a valid index event |
|
|
|
|
const publicationTree = indexEvent ? new SveltePublicationTree(indexEvent, data.ndk) : null; |
|
|
|
|
const toc = indexEvent ? new TableOfContents( |
|
|
|
|
indexEvent.tagAddress(), |
|
|
|
|
publicationTree, |
|
|
|
|
publicationTree!, |
|
|
|
|
page.url.pathname ?? "", |
|
|
|
|
); |
|
|
|
|
) : null; |
|
|
|
|
|
|
|
|
|
setContext("publicationTree", publicationTree); |
|
|
|
|
setContext("toc", toc); |
|
|
|
|
setContext("asciidoctor", Processor()); |
|
|
|
|
|
|
|
|
|
// Only set up bookmark handling if we have a valid publication tree |
|
|
|
|
if (publicationTree && indexEvent) { |
|
|
|
|
publicationTree.onBookmarkMoved((address) => { |
|
|
|
|
goto(`#${address}`, { |
|
|
|
|
replaceState: true, |
|
|
|
|
@ -45,8 +51,12 @@
@@ -45,8 +51,12 @@
|
|
|
|
|
store.put({ key: bookmarkKey, address }); |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onMount(() => { |
|
|
|
|
// Only handle bookmarks if we have valid components |
|
|
|
|
if (!publicationTree || !indexEvent) return; |
|
|
|
|
|
|
|
|
|
// TODO: Extract IndexedDB interaction to a service layer. |
|
|
|
|
// Read bookmark from IndexedDB |
|
|
|
|
const db = indexedDB.open("alexandria", 1); |
|
|
|
|
@ -81,6 +91,7 @@
@@ -81,6 +91,7 @@
|
|
|
|
|
}); |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
{#if indexEvent && data.indexEvent} |
|
|
|
|
<ArticleNav |
|
|
|
|
publicationType={data.publicationType} |
|
|
|
|
rootId={data.indexEvent.id} |
|
|
|
|
@ -94,3 +105,10 @@
@@ -94,3 +105,10 @@
|
|
|
|
|
indexEvent={indexEvent} |
|
|
|
|
/> |
|
|
|
|
</main> |
|
|
|
|
{:else} |
|
|
|
|
<main class="publication"> |
|
|
|
|
<div class="flex items-center justify-center min-h-screen"> |
|
|
|
|
<p class="text-gray-600 dark:text-gray-400">Loading publication...</p> |
|
|
|
|
</div> |
|
|
|
|
</main> |
|
|
|
|
{/if} |