From 03612ad6de7a63869353d645db5c71e1ee5da2e2 Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Tue, 15 Apr 2025 09:32:43 -0500 Subject: [PATCH] Render publication content and headers Incomplete. Some headers are still missing, and we don't yet gracefully handle events that can't be found. --- src/lib/components/Publication.svelte | 10 ++- src/lib/components/PublicationSection.svelte | 84 +++++++++++++++++--- src/routes/publication/+page.svelte | 2 + 3 files changed, 79 insertions(+), 17 deletions(-) diff --git a/src/lib/components/Publication.svelte b/src/lib/components/Publication.svelte index 167cf67..8bcf5a4 100644 --- a/src/lib/components/Publication.svelte +++ b/src/lib/components/Publication.svelte @@ -39,8 +39,9 @@ for (let i = 0; i < count; i++) { const nextItem = await publicationTree.next(); - if (nextItem.done) { - break; + if (leaves.includes(nextItem.value) || nextItem.done) { + isLoading = false; + return; } leaves.push(nextItem.value); } @@ -136,11 +137,11 @@ observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (entry.isIntersecting && !isLoading) { - loadMore(8); + loadMore(4); } }); }, { threshold: 0.5 }); - loadMore(16); + loadMore(8); return () => { window.removeEventListener("hashchange", scrollToElementWithOffset); @@ -186,6 +187,7 @@ {#each leaves as leaf, i} setLastElementRef(el, i)} /> diff --git a/src/lib/components/PublicationSection.svelte b/src/lib/components/PublicationSection.svelte index 8dfa42f..0ea64f1 100644 --- a/src/lib/components/PublicationSection.svelte +++ b/src/lib/components/PublicationSection.svelte @@ -1,27 +1,82 @@
- {#await Promise.all([sectionEvent, publicationType])} + {#await Promise.all([leafContent, publicationType, divergingBranches])} - {:then [sectionEvent, publicationType]} - - {@render contentParagraph(sectionEvent?.content ?? '', publicationType ?? 'article', false)} + {:then [leafContent, publicationType, divergingBranches]} + + {#each divergingBranches as [branch, depth]} + {@render sectionHeading(branch.getMatchingTags('title')[0]?.[1] ?? '', depth)} + {/each} + {@render contentParagraph(leafContent.toString(), publicationType ?? 'article', false)} {/await}
diff --git a/src/routes/publication/+page.svelte b/src/routes/publication/+page.svelte index 59fa70c..9e9bf1d 100644 --- a/src/routes/publication/+page.svelte +++ b/src/routes/publication/+page.svelte @@ -4,12 +4,14 @@ import type { PageProps } from "./$types"; import { onDestroy, setContext } from "svelte"; import { PublicationTree } from "$lib/data_structures/publication_tree"; + import Processor from "asciidoctor"; let { data }: PageProps = $props(); const publicationTree = new PublicationTree(data.indexEvent, data.ndk); setContext('publicationTree', publicationTree); + setContext('asciidoctor', Processor()); // Get publication metadata for OpenGraph tags let title = $derived(data.indexEvent?.getMatchingTags('title')[0]?.[1] || data.parser?.getIndexTitle(data.parser?.getRootIndexId()) || 'Alexandria Publication');