From 9f0c38255b36516bbce85de0a7fb4b3076b3c6c7 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Mon, 20 Apr 2026 13:08:07 -0400 Subject: [PATCH] fix published footnote count --- .../[rkey]/Footnotes/PublishedFootnotes.tsx | 61 ++++++++++++++++--- .../[publication]/[rkey]/PostContent.tsx | 10 +++ 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/app/lish/[did]/[publication]/[rkey]/Footnotes/PublishedFootnotes.tsx b/app/lish/[did]/[publication]/[rkey]/Footnotes/PublishedFootnotes.tsx index deeec557..92e199f2 100644 --- a/app/lish/[did]/[publication]/[rkey]/Footnotes/PublishedFootnotes.tsx +++ b/app/lish/[did]/[publication]/[rkey]/Footnotes/PublishedFootnotes.tsx @@ -5,6 +5,8 @@ import { PubLeafletBlocksText, PubLeafletBlocksHeader, PubLeafletBlocksBlockquote, + PubLeafletBlocksOrderedList, + PubLeafletBlocksUnorderedList, PubLeafletPagesLinearDocument, } from "lexicons/api"; import { TextBlockCore } from "../Blocks/TextBlockCore"; @@ -29,7 +31,6 @@ export function collectFootnotesFromBlocks( function scanFacets(facets?: PubLeafletRichtextFacet.Main[]) { if (!facets || !Array.isArray(facets)) return; - console.log(facets); for (let facet of facets) { for (let feature of facet.features) { if (PubLeafletRichtextFacet.isFootnote(feature)) { @@ -47,17 +48,59 @@ export function collectFootnotesFromBlocks( } } + function scanBlockContent( + content: + | PubLeafletBlocksText.Main + | PubLeafletBlocksHeader.Main + | PubLeafletBlocksBlockquote.Main + | { $type?: string }, + ) { + if (PubLeafletBlocksText.isMain(content)) { + scanFacets(content.facets); + } else if (PubLeafletBlocksHeader.isMain(content)) { + scanFacets(content.facets); + } else if (PubLeafletBlocksBlockquote.isMain(content)) { + scanFacets(content.facets); + } + } + + function scanOrderedListItems( + items: PubLeafletBlocksOrderedList.ListItem[], + ) { + for (let item of items) { + scanBlockContent(item.content); + if (item.children?.length) { + scanOrderedListItems(item.children); + } + if (item.unorderedListChildren?.children?.length) { + scanUnorderedListItems(item.unorderedListChildren.children); + } + } + } + + function scanUnorderedListItems( + items: PubLeafletBlocksUnorderedList.ListItem[], + ) { + for (let item of items) { + scanBlockContent(item.content); + if (item.children?.length) { + scanUnorderedListItems(item.children); + } + if (item.orderedListChildren?.children?.length) { + scanOrderedListItems(item.orderedListChildren.children); + } + } + } + for (let b of blocks) { let block = b.block; - let facets: PubLeafletRichtextFacet.Main[] | undefined; - if (PubLeafletBlocksText.isMain(block)) { - facets = block.facets; - } else if (PubLeafletBlocksHeader.isMain(block)) { - facets = block.facets; - } else if (PubLeafletBlocksBlockquote.isMain(block)) { - facets = block.facets; + if (PubLeafletBlocksOrderedList.isMain(block)) { + scanOrderedListItems(block.children); + } else if (PubLeafletBlocksUnorderedList.isMain(block)) { + scanUnorderedListItems(block.children); + } else { + scanBlockContent(block); } - if (facets) scanFacets(facets); } return footnotes; diff --git a/app/lish/[did]/[publication]/[rkey]/PostContent.tsx b/app/lish/[did]/[publication]/[rkey]/PostContent.tsx index 81cc2a85..e6164175 100644 --- a/app/lish/[did]/[publication]/[rkey]/PostContent.tsx +++ b/app/lish/[did]/[publication]/[rkey]/PostContent.tsx @@ -256,6 +256,7 @@ export let Block = ({ key={i} className={className} pageId={pageId} + footnoteIndexMap={footnoteIndexMap} /> ))} @@ -277,6 +278,7 @@ export let Block = ({ className={className} pageId={pageId} startIndex={block.startIndex || 1} + footnoteIndexMap={footnoteIndexMap} /> ))} @@ -547,6 +549,7 @@ function ListItem(props: { bskyPostData: AppBskyFeedDefs.PostView[]; pollData: PollData[]; pageId?: string; + footnoteIndexMap?: Map; }) { let children = props.item.children?.length ? ( @@ -579,6 +583,7 @@ function ListItem(props: { className={props.className} pageId={props.pageId} startIndex={props.item.orderedListChildren?.startIndex} + footnoteIndexMap={props.footnoteIndexMap} /> ))} @@ -606,6 +611,7 @@ function ListItem(props: { isList index={props.index} pageId={props.pageId} + footnoteIndexMap={props.footnoteIndexMap} /> {children} {orderedChildren} @@ -624,6 +630,7 @@ function OrderedListItem(props: { pollData: PollData[]; pageId?: string; startIndex?: number; + footnoteIndexMap?: Map; }) { const calculatedIndex = (props.startIndex || 1) + props.index[props.index.length - 1]; @@ -641,6 +648,7 @@ function OrderedListItem(props: { className={props.className} pageId={props.pageId} startIndex={props.startIndex} + footnoteIndexMap={props.footnoteIndexMap} /> ))} @@ -658,6 +666,7 @@ function OrderedListItem(props: { key={index} className={props.className} pageId={props.pageId} + footnoteIndexMap={props.footnoteIndexMap} /> ))} @@ -685,6 +694,7 @@ function OrderedListItem(props: { isList index={props.index} pageId={props.pageId} + footnoteIndexMap={props.footnoteIndexMap} /> {children} {unorderedChildren} -- 2.51.2