in modules/nuxt_lunr_content_bridge.js [26:51]
export default function NuxtLunrContentBridge() {
const parser = new MarkdownParser({});
// Listen to new documents being added to the database
this.nuxt.hook('content:file:beforeInsert', (document) => {
if (document.extension === '.md') {
// Add document to the search index
this.nuxt.callHook('lunr:document', {
document: {
id: document.slug,
title: document.name,
/*
document.body is a parsed AST of the markdown document
The MarkdownParser has a method to extract the text only nodes,
which we can reuse here
*/
body: cleanText(parser.flattenNodeText(document.body)),
},
meta: {
title: `${startCase(document.dir)} > ${document.name}`,
route: document.path,
},
});
}
});
}