Skip to content

Commit 35b9406

Browse files
committed
search - index pre-section paragraphs in main and specifically-designated objects
1 parent 11c639d commit 35b9406

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/project/types/website/website-search.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,31 @@ export async function updateSearchIndex(
326326

327327
// If there are any paragraphs residing outside a section, just
328328
// include that in the document entry
329-
const pararaphNodes = doc.querySelectorAll(
330-
`${mainSelector} > p, ${mainSelector} > div.cell`,
329+
const paragraphNodes = doc.querySelectorAll(
330+
`${mainSelector} > p, ${mainSelector} > div.cell, main > p`,
331331
);
332332

333-
for (const paragraphNode of pararaphNodes) {
333+
const addToIndex = (paragraphNode: Element) => {
334334
const text = paragraphNode.textContent.trim();
335335
if (text) {
336336
pageText.push(text);
337337
}
338338

339339
// Since these are already indexed with the main entry, remove them
340340
// so they are not indexed again
341-
(paragraphNode as Element).remove();
341+
paragraphNode.remove();
342+
};
343+
344+
for (const paragraphNode of paragraphNodes) {
345+
addToIndex(paragraphNode as Element);
346+
}
347+
348+
// Add forced inclusions to the index
349+
const forcedInclusions = doc.querySelectorAll(
350+
`.quarto-include-in-search-index`,
351+
);
352+
for (const forcedInclusion of forcedInclusions) {
353+
addToIndex(forcedInclusion as Element);
342354
}
343355

344356
if (pageText.length > 0) {

0 commit comments

Comments
 (0)