|
|
|
|
@ -15,8 +15,10 @@
@@ -15,8 +15,10 @@
|
|
|
|
|
oncursorrelease, |
|
|
|
|
parentId, |
|
|
|
|
rootId, |
|
|
|
|
index, |
|
|
|
|
sectionClass, |
|
|
|
|
publicationType, |
|
|
|
|
onBlogUpdate |
|
|
|
|
} = $props<{ |
|
|
|
|
allowEditing?: boolean; |
|
|
|
|
depth?: number; |
|
|
|
|
@ -26,14 +28,19 @@
@@ -26,14 +28,19 @@
|
|
|
|
|
oncursorrelease?: (e: MouseEvent) => void; |
|
|
|
|
parentId?: string | null | undefined; |
|
|
|
|
rootId: string; |
|
|
|
|
index: number; |
|
|
|
|
sectionClass?: string; |
|
|
|
|
publicationType?: string; |
|
|
|
|
onBlogUpdate?: any; |
|
|
|
|
}>(); |
|
|
|
|
|
|
|
|
|
let currentContent: string = $state($pharosInstance.getContent(rootId)); |
|
|
|
|
let title: string | undefined = $state($pharosInstance.getIndexTitle(rootId)); |
|
|
|
|
let orderedChildren: string[] = $state($pharosInstance.getOrderedChildIds(rootId)); |
|
|
|
|
|
|
|
|
|
let blogEntries = $state(Array.from($pharosInstance.getBlogEntries())); |
|
|
|
|
let metadata = $state($pharosInstance.getIndexMetadata()); |
|
|
|
|
|
|
|
|
|
let isEditing: boolean = $state(false); |
|
|
|
|
let hasCursor: boolean = $state(false); |
|
|
|
|
let childHasCursor: boolean = $state(false); |
|
|
|
|
@ -85,6 +92,44 @@
@@ -85,6 +92,44 @@
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
function byline(rootId: string, index: number) { |
|
|
|
|
console.log(rootId, index, blogEntries); |
|
|
|
|
const event = blogEntries[index][1]; |
|
|
|
|
const author = event ? event.getMatchingTags("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] : ''; |
|
|
|
|
return image ?? ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function publishedAt(rootId: string, index: number) { |
|
|
|
|
console.log(rootId, index); |
|
|
|
|
console.log(blogEntries[index]); |
|
|
|
|
const event = blogEntries[index][1]; |
|
|
|
|
const date = event.created_at ? new Date(event.created_at * 1000) : ''; |
|
|
|
|
if (date !== '') { |
|
|
|
|
const formattedDate = new Intl.DateTimeFormat("en-US", { |
|
|
|
|
year: "numeric", |
|
|
|
|
month: "short", |
|
|
|
|
day: "2-digit", |
|
|
|
|
}).format(date); |
|
|
|
|
return formattedDate ?? ""; |
|
|
|
|
} |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function readBlog(rootId:string) { |
|
|
|
|
onBlogUpdate?.(rootId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function propagateBlogUpdate(rootId:string) { |
|
|
|
|
onBlogUpdate?.(rootId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function handleMouseEnter(e: MouseEvent) { |
|
|
|
|
hasCursor = true; |
|
|
|
|
if (oncursorcapture) { |
|
|
|
|
@ -177,11 +222,38 @@
@@ -177,11 +222,38 @@
|
|
|
|
|
{/if} |
|
|
|
|
{/snippet} |
|
|
|
|
|
|
|
|
|
{#snippet coverImage(rootId: string, index: number, depth: number)} |
|
|
|
|
{#if hasCoverImage(rootId, index)} |
|
|
|
|
<div class="coverImage depth-{depth}"> |
|
|
|
|
<img src={hasCoverImage(rootId, index)} > |
|
|
|
|
</div> |
|
|
|
|
{/if} |
|
|
|
|
{/snippet} |
|
|
|
|
|
|
|
|
|
{#snippet blogMetadata(rootId: string, index: number)} |
|
|
|
|
<p class='h-leather'> |
|
|
|
|
by {byline(rootId, index)} |
|
|
|
|
</p> |
|
|
|
|
<p class='h-leather italic text-sm'> |
|
|
|
|
{publishedAt(rootId, index)} |
|
|
|
|
</p> |
|
|
|
|
{/snippet} |
|
|
|
|
|
|
|
|
|
{#snippet readMoreLink(rootId: string, index: number)} |
|
|
|
|
<p class='h-leather'> |
|
|
|
|
<button class="underline" onclick={() => readBlog(rootId)}>Read all about it...</button> |
|
|
|
|
</p> |
|
|
|
|
{/snippet} |
|
|
|
|
|
|
|
|
|
{#snippet contentParagraph(content: string, publicationType: string)} |
|
|
|
|
{#if publicationType === 'novel'} |
|
|
|
|
<P class='whitespace-normal' firstupper={isSectionStart}> |
|
|
|
|
{@html content} |
|
|
|
|
</P> |
|
|
|
|
{:else if publicationType === 'blog'} |
|
|
|
|
<P class='whitespace-normal' firstupper={false}> |
|
|
|
|
{@html content} |
|
|
|
|
</P> |
|
|
|
|
{:else} |
|
|
|
|
<P class='whitespace-normal' firstupper={false}> |
|
|
|
|
{@html content} |
|
|
|
|
@ -239,15 +311,25 @@
@@ -239,15 +311,25 @@
|
|
|
|
|
Save |
|
|
|
|
</Button> |
|
|
|
|
</ButtonGroup> |
|
|
|
|
{:else} |
|
|
|
|
{#if publicationType === 'blog' && depth === 1} |
|
|
|
|
{@render coverImage(rootId, index, depth)} |
|
|
|
|
{@render sectionHeading(title!, depth)} |
|
|
|
|
{@render blogMetadata(rootId, index)} |
|
|
|
|
{:else} |
|
|
|
|
{@render sectionHeading(title!, depth)} |
|
|
|
|
{/if} |
|
|
|
|
{/if} |
|
|
|
|
<!-- Recurse on child indices and zettels --> |
|
|
|
|
{#if publicationType === 'blog' && depth === 1} |
|
|
|
|
{@render readMoreLink(rootId, index)} |
|
|
|
|
{:else } |
|
|
|
|
{#key subtreeUpdateCount} |
|
|
|
|
{#each orderedChildren as id, index} |
|
|
|
|
<Self |
|
|
|
|
rootId={id} |
|
|
|
|
parentId={rootId} |
|
|
|
|
index={index} |
|
|
|
|
publicationType={publicationType} |
|
|
|
|
depth={depth + 1} |
|
|
|
|
{allowEditing} |
|
|
|
|
@ -256,9 +338,11 @@
@@ -256,9 +338,11 @@
|
|
|
|
|
bind:needsUpdate={subtreeNeedsUpdate} |
|
|
|
|
oncursorcapture={handleChildCursorCaptured} |
|
|
|
|
oncursorrelease={handleChildCursorReleased} |
|
|
|
|
onBlogUpdate={propagateBlogUpdate} |
|
|
|
|
/> |
|
|
|
|
{/each} |
|
|
|
|
{/key} |
|
|
|
|
{/if} |
|
|
|
|
</div> |
|
|
|
|
{/if} |
|
|
|
|
{#if allowEditing && depth > 0} |
|
|
|
|
|