From 78378f3bfaecd1d17c55edacf45aa4da87f9c6a7 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Sun, 7 Jul 2024 03:07:43 -0400 Subject: [PATCH] add description metadata --- app/[doc_id]/page.tsx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/[doc_id]/page.tsx b/app/[doc_id]/page.tsx index fab38db7..aba4ba5d 100644 --- a/app/[doc_id]/page.tsx +++ b/app/[doc_id]/page.tsx @@ -86,11 +86,11 @@ export async function generateMetadata(props: Props): Promise { .sort((a, b) => (a.position > b.position ? 1 : -1)) .filter((b) => b.type === "text" || b.type === "heading"); - let metadata: Metadata = { title: "Untitled Leaflet", description: "" }; - let firstBlock = blocks[0]; - if (firstBlock?.type === "heading") { + let metadata: Metadata = { title: "Untitled Leaflet", description: " " }; + let block = blocks[0]; + if (block?.type === "heading") { let content = initialFacts.find( - (f) => f.entity === firstBlock.value && f.attribute === "block/text", + (f) => f.entity === block.value && f.attribute === "block/text", ) as Fact<"block/text"> | undefined; if (content) { let doc = new Y.Doc(); @@ -99,6 +99,18 @@ export async function generateMetadata(props: Props): Promise { let nodes = doc.getXmlElement("prosemirror").toArray(); metadata.title = YJSFragmentToString(nodes[0]); } + block = blocks[1]; } + let content = initialFacts.find( + (f) => f.entity === block.value && f.attribute === "block/text", + ) as Fact<"block/text"> | undefined; + if (content) { + let doc = new Y.Doc(); + const update = base64.toByteArray(content.data.value); + Y.applyUpdate(doc, update); + let nodes = doc.getXmlElement("prosemirror").toArray(); + metadata.description = YJSFragmentToString(nodes[0]); + } + return metadata; } -- 2.51.2