From c16939706eec90b8e0dc0482be7f7baf45d225a6 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Fri, 27 Feb 2026 00:47:17 -0500 Subject: [PATCH] add missing util --- src/utils/getFirstParagraph.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/utils/getFirstParagraph.ts diff --git a/src/utils/getFirstParagraph.ts b/src/utils/getFirstParagraph.ts new file mode 100644 index 00000000..7a0f1d36 --- /dev/null +++ b/src/utils/getFirstParagraph.ts @@ -0,0 +1,19 @@ +import type { NormalizedDocument } from "src/utils/normalizeRecords"; +import type { PubLeafletContent } from "lexicons/api"; + +export function getFirstParagraph( + doc: NormalizedDocument, +): string | undefined { + let content = doc.content; + if (!content || !("pages" in content)) return; + let pages = (content as PubLeafletContent.Main).pages; + if (!pages?.[0]) return; + let page = pages[0]; + if (!("blocks" in page)) return; + for (let blockWrapper of (page as { blocks: { block: any }[] }).blocks) { + let block = blockWrapper.block; + if (block?.$type === "pub.leaflet.blocks.text" && block.plaintext) { + return block.plaintext; + } + } +} -- 2.51.2