a tool for shared writing and social publishing

add description metadata

+16 -4
+16 -4
app/[doc_id]/page.tsx
··· 86 86 .sort((a, b) => (a.position > b.position ? 1 : -1)) 87 87 .filter((b) => b.type === "text" || b.type === "heading"); 88 88 89 - let metadata: Metadata = { title: "Untitled Leaflet", description: "" }; 90 - let firstBlock = blocks[0]; 91 - if (firstBlock?.type === "heading") { 89 + let metadata: Metadata = { title: "Untitled Leaflet", description: " " }; 90 + let block = blocks[0]; 91 + if (block?.type === "heading") { 92 92 let content = initialFacts.find( 93 - (f) => f.entity === firstBlock.value && f.attribute === "block/text", 93 + (f) => f.entity === block.value && f.attribute === "block/text", 94 94 ) as Fact<"block/text"> | undefined; 95 95 if (content) { 96 96 let doc = new Y.Doc(); ··· 99 99 let nodes = doc.getXmlElement("prosemirror").toArray(); 100 100 metadata.title = YJSFragmentToString(nodes[0]); 101 101 } 102 + block = blocks[1]; 102 103 } 104 + let content = initialFacts.find( 105 + (f) => f.entity === block.value && f.attribute === "block/text", 106 + ) as Fact<"block/text"> | undefined; 107 + if (content) { 108 + let doc = new Y.Doc(); 109 + const update = base64.toByteArray(content.data.value); 110 + Y.applyUpdate(doc, update); 111 + let nodes = doc.getXmlElement("prosemirror").toArray(); 112 + metadata.description = YJSFragmentToString(nodes[0]); 113 + } 114 + 103 115 return metadata; 104 116 }