A Metalsmith plugin that integrates the Lunr.js client side search engine.
Builds a searchable JSON index based on Metalsmith metadata.
Made because metalsmith-lunr does not work with Lunr 2.0.
$ npm install metalsmith-lunr-index
Include metalsmith-lunr-index in your metalsmith pipeline.
Metalsmith-lunr can be used without options:
var lunr = require('metalsmith-lunr-index');
metalsmith.use(lunr());
By passsing in certain properties, you can change the behaviour.
option | meaning |
---|---|
pattern |
Glob pattern for selecting files to index default: ['**/*.html'] |
indexPath |
Output path for the index default: search-index.json |
removeStemmer |
true or false , removes the stemmer from the indexing pipeline |
refKey |
property to be used as ref - if not defined path is used |
Metalsmith-lunr-index will generate search-index.json. Include lunr.js in your javascript source files. Client side search example can be found here.
Once the JSON file has been parsed into javascript, simply run the following:
//index is the parsed JSON file
var idx = lunr.Index.load(index);
var results = idx.search("Your Search Terms Here");