@pirxpilot/metalsmith-lunr-index

1.0.1 • Public • Published

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.

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

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

Package Sidebar

Install

npm i @pirxpilot/metalsmith-lunr-index

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

3.33 kB

Total Files

3

Last publish

Collaborators

  • pirxpilot