Simplify search configuration

This commit is contained in:
Ben Edgington
2023-06-08 09:02:23 +01:00
parent 80db828061
commit 22727fc4de
2 changed files with 11 additions and 6 deletions

View File

@@ -112,8 +112,6 @@ module.exports = {
pages: [],
// Elements matching this query are ignored completely, including their text:
ignore: 'svg, details, mtable, mrow, [aria-hidden="true"], .footnote-ref',
// Chunks matching this query are excluded as duplicates (to handle nested matches):
dedup: '[id^="fn-"] *, figcaption *, li *',
}
},
}

View File

@@ -21,12 +21,15 @@ const getChunks = ($, node, chunkTypes, exclude, counts) => {
}
const chunks = []
let matchedChunk = false;
for (let idx = 0; idx < chunkTypes.length; idx++) {
const type = chunkTypes[idx]
if ($(node).is(type.query)) {
matchedChunk = true
const tagName = $(node).prop('tagName').toLowerCase()
let id = $(node).attr('id')
if ( id === undefined) {
@@ -46,13 +49,17 @@ const getChunks = ($, node, chunkTypes, exclude, counts) => {
weight: type.weight === undefined ? 1 : type.weight,
})
}
break
}
}
$(node).children().not(exclude.ignore).not(exclude.dedup).each(function (i, e) {
chunks.push(...getChunks($, e, chunkTypes, exclude, counts))
})
// We shouldn't recurse into chunks that we've already done
if (!matchedChunk) {
$(node).children().not(exclude.ignore).each(function (i, e) {
chunks.push(...getChunks($, e, chunkTypes, exclude, counts))
})
}
return chunks
}
@@ -82,7 +89,7 @@ exports.createPages = async (
const {
enabled = true,
chunkTypes = [],
exclude = {frontmatter: [], pages: [], ignore: '', dedup: ''},
exclude = {frontmatter: [], pages: [], ignore: ''},
} = pluginOptions
const result = await graphql(`