1.0.1 • Published 1 year ago

@pirxpilot/metalsmith-lunr-index v1.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
1 year ago

metalsmith-lunr-index

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.

Installation

$ npm install metalsmith-lunr-index

Usage

Include metalsmith-lunr-index in your metalsmith pipeline.

Metalsmith-lunr can be used without options:

var lunr = require('metalsmith-lunr-index');

metalsmith.use(lunr());

Options

By passsing in certain properties, you can change the behaviour.

optionmeaning
patternGlob pattern for selecting files to index default: '**/*.html'
indexPathOutput path for the index default: search-index.json
removeStemmertrue or false, removes the stemmer from the indexing pipeline
refKeyproperty to be used as ref - if not defined path is used

Client Side Search

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");