Skip to content

Commit 537c06a

Browse files
committed
Improve first paragraph detection
1 parent d42edf8 commit 537c06a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/project/types/website/listing/website-listing-shared.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,26 @@ export function readRenderedContents(
418418
}
419419
};
420420

421+
// Try to find a paragraph that doesn't resolve as completely empty
422+
// This could happen, for example, if images are removed from the document
423+
// and the first paragraph is an image.
424+
const getFirstPara = () => {
425+
const paraNodes = mainEl?.querySelectorAll("p");
426+
if (paraNodes) {
427+
for (const paraNode of paraNodes) {
428+
const paraContents = cleanMath((paraNode as Element).innerHTML);
429+
if (paraContents) {
430+
return paraContents;
431+
}
432+
}
433+
}
434+
return undefined;
435+
};
436+
421437
return {
422438
title: titleText,
423439
fullContents: cleanMath(mainEl?.innerHTML),
424-
firstPara: cleanMath(mainEl?.querySelector("p")?.innerHTML),
440+
firstPara: getFirstPara(),
425441
};
426442
}
427443

0 commit comments

Comments
 (0)