Generate Fuse index with Node.js
Cheerio is a fast, flexible, and elegant library for parsing and manipulating HTML and XML. Fuse.js is a lightweight fuzzy-search, in JavaScript, with zero dependencies.
With Node.js, use Cheerio to manipulate HTML, then select elements to generate Fuse index.
const fs = require('fs'); const cheerio = require('cheerio'); const entries = []; for (const file in htmlFiles) { const htmlContent = fs.readFileSync(file, {encoding: 'utf8', flag: 'r'}); const $ = cheerio.load(htmlContent); const title = $('title').text(); const description = $('meta[name=description]').attr('content'); const keywords = $('meta[name=keywords]').attr('content'); const url = '/posts/' + file; entries.push({ title: title || '', description: description || '', keywords: keywords || '', url: url }); } console.log(JSON.stringify(entries));