|
|
|
@ -1,23 +1,40 @@ |
|
|
|
import { error } from "@sveltejs/kit"; |
|
|
|
import { error } from "@sveltejs/kit"; |
|
|
|
import type { LayoutServerLoad } from "./$types"; |
|
|
|
import type { LayoutServerLoad } from "./$types"; |
|
|
|
|
|
|
|
import { fetchEventByDTag, fetchEventById, fetchEventByNaddr, fetchEventByNevent } from "../../../../lib/utils/websocket_utils.ts"; |
|
|
|
|
|
|
|
import type { NostrEvent } from "../../../../lib/utils/websocket_utils.ts"; |
|
|
|
|
|
|
|
|
|
|
|
export const load: LayoutServerLoad = async ({ params, url }) => { |
|
|
|
export const load: LayoutServerLoad = async ({ params, url }) => { |
|
|
|
const { type, identifier } = params; |
|
|
|
const { type, identifier } = params; |
|
|
|
|
|
|
|
|
|
|
|
// Validate the identifier type for SSR
|
|
|
|
let indexEvent: NostrEvent; |
|
|
|
const validTypes = ['id', 'd', 'naddr', 'nevent']; |
|
|
|
|
|
|
|
if (!validTypes.includes(type)) { |
|
|
|
// Handle different identifier types
|
|
|
|
|
|
|
|
switch (type) { |
|
|
|
|
|
|
|
case 'id': |
|
|
|
|
|
|
|
indexEvent = await fetchEventById(identifier); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'd': |
|
|
|
|
|
|
|
indexEvent = await fetchEventByDTag(identifier); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'naddr': |
|
|
|
|
|
|
|
indexEvent = await fetchEventByNaddr(identifier); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'nevent': |
|
|
|
|
|
|
|
indexEvent = await fetchEventByNevent(identifier); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
error(400, `Unsupported identifier type: ${type}`); |
|
|
|
error(400, `Unsupported identifier type: ${type}`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Provide basic metadata for SSR - actual fetching will happen on client
|
|
|
|
// Extract metadata for meta tags
|
|
|
|
const title = "Alexandria Publication"; |
|
|
|
const title = indexEvent.tags.find((tag) => tag[0] === "title")?.[1] || "Alexandria Publication"; |
|
|
|
const summary = "Alexandria is a digital library, utilizing Nostr events for curated publications and wiki pages."; |
|
|
|
const summary = indexEvent.tags.find((tag) => tag[0] === "summary")?.[1] ||
|
|
|
|
const image = "/screenshots/old_books.jpg"; |
|
|
|
"Alexandria is a digital library, utilizing Nostr events for curated publications and wiki pages."; |
|
|
|
|
|
|
|
const image = indexEvent.tags.find((tag) => tag[0] === "image")?.[1] || "/screenshots/old_books.jpg"; |
|
|
|
const currentUrl = `${url.origin}${url.pathname}`; |
|
|
|
const currentUrl = `${url.origin}${url.pathname}`; |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
indexEvent: null, // Will be fetched on client side
|
|
|
|
indexEvent, |
|
|
|
metadata: { |
|
|
|
metadata: { |
|
|
|
title, |
|
|
|
title, |
|
|
|
summary, |
|
|
|
summary, |
|
|
|
|