{title}
-by
- {#if originalAuthor !== null}
-
- {:else}
- {author}
- {/if}
-
- Version: {version}
-{summary}
-Index author:
- Source: {source}
- {/if} - {#if type !== null} -Publication type: {type}
- {/if} - {#if language !== null} -Language: {language}
- {/if} - {#if publisher !== null} -Published by: {publisher}
- {/if} - {#if identifier !== null} -{identifier}
- {/if} - -{title}
+by
+ {#if originalAuthor !== null}
+
+ {:else}
+ {author}
+ {/if}
+
+ Version: {version}
+{summary}
+Index author:
+Source: {source}
+ {/if} + {#if type !== null} +Publication type: {type}
+ {/if} + {#if language !== null} +Language: {language}
+ {/if} + {#if publisher !== null} +Published by: {publisher}
+ {/if} + {#if identifier !== null} +{identifier}
+ {/if} + +Alexandria
diff --git a/src/lib/components/Preview.svelte b/src/lib/components/Preview.svelte index f7dfe03..44e6c83 100644 --- a/src/lib/components/Preview.svelte +++ b/src/lib/components/Preview.svelte @@ -15,8 +15,10 @@ oncursorrelease, parentId, rootId, + index, sectionClass, publicationType, + onBlogUpdate } = $props<{ allowEditing?: boolean; depth?: number; @@ -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 @@ } }); + 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 @@ {/if} {/snippet} +{#snippet coverImage(rootId: string, index: number, depth: number)} + {#if hasCoverImage(rootId, index)} ++ by {byline(rootId, index)} +
++ {publishedAt(rootId, index)} +
+{/snippet} + +{#snippet readMoreLink(rootId: string, index: number)} +
+
{@html content}
+ {:else if publicationType === 'blog'} ++ {@html content} +
{:else}
{@html content}
@@ -240,25 +312,37 @@
{:else}
- {@render sectionHeading(title!, depth)}
+ {#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}
- {#key subtreeUpdateCount}
- {#each orderedChildren as id, index}
-