From f240083dac71fcb60d2958a4f7e88d8b8f31879a Mon Sep 17 00:00:00 2001 From: Silberengel Date: Sat, 12 Apr 2025 18:50:26 +0200 Subject: [PATCH 1/5] implemen OpenGraph metadata --- src/lib/components/Publication.svelte | 48 ++++++++++++++++++++++++-- src/routes/publication/+page.svelte | 16 +++++++-- src/routes/publication/+page.ts | 5 +-- static/screenshots/old_books.jpg | Bin 0 -> 207556 bytes 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 static/screenshots/old_books.jpg diff --git a/src/lib/components/Publication.svelte b/src/lib/components/Publication.svelte index 0794cc9..9d79264 100644 --- a/src/lib/components/Publication.svelte +++ b/src/lib/components/Publication.svelte @@ -14,8 +14,28 @@ import Preview from "./Preview.svelte"; import { pharosInstance } from "$lib/parser"; import { page } from "$app/state"; - - let { rootId, publicationType } = $props<{ rootId: string, publicationType: string }>(); + import { ndkInstance } from "$lib/ndk"; + import type { NDKEvent } from "@nostr-dev-kit/ndk"; + + let { rootId, publicationType, indexEvent } = $props<{ + rootId: string, + publicationType: string, + indexEvent: NDKEvent + }>(); + + // Get publication metadata for OpenGraph tags + let title = $derived($pharosInstance.getIndexTitle(rootId) || 'Alexandria Publication'); + let currentUrl = page.url.href; + + // Get image and summary from the event tags if available + // If image unavailable, use the Alexandria default pic. + let image = $derived(indexEvent?.getMatchingTags('image')[0]?.[1] || '/screenshots/old_books.jpg'); + let summary = $derived(indexEvent?.getMatchingTags('summary')[0]?.[1] || ``); + + // Debug: Log the event and its tags + console.log('indexEvent:', indexEvent); + console.log('image tag:', indexEvent?.getMatchingTags('image')); + console.log('summary tag:', indexEvent?.getMatchingTags('summary')); if (rootId !== $pharosInstance.getRootIndexId()) { console.error("Root ID does not match parser root index ID"); @@ -94,6 +114,30 @@ }); + + + {title} + + + + + + + + + {#if image} + + {/if} + + + + + + {#if image} + + {/if} + + {#if showTocButton && !showToc}