a tool for shared writing and social publishing
at main 19 lines 659 B view raw
1import type { NormalizedDocument } from "src/utils/normalizeRecords"; 2import type { PubLeafletContent } from "lexicons/api"; 3 4export function getFirstParagraph( 5 doc: NormalizedDocument, 6): string | undefined { 7 let content = doc.content; 8 if (!content || !("pages" in content)) return; 9 let pages = (content as PubLeafletContent.Main).pages; 10 if (!pages?.[0]) return; 11 let page = pages[0]; 12 if (!("blocks" in page)) return; 13 for (let blockWrapper of (page as { blocks: { block: any }[] }).blocks) { 14 let block = blockWrapper.block; 15 if (block?.$type === "pub.leaflet.blocks.text" && block.plaintext) { 16 return block.plaintext; 17 } 18 } 19}