Metalsmith plugin to generate a json file of metadata for use in conjunction with metalsmith-lunr
Branch: master
Clone or download
Pull request Compare This branch is even with sarahhenderson:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


A Metalsmith plugin that generates file metadata to use in conjuction with metalsmith-lunr and lunr.js.

The metalsmith-lunr plugin generates a search index JSON file. The lunr search engine uses this to perform a search and returns the keys that match. I wanted to display some post metadata in the search results view, and so I created this plugin to generate a metadata file using the same keys to use in my search results page.


The plugin indexes the same set of files as the metalsmith-lunr plugin: files with lunr: true set in the metadata.

You need to specify the path where the metadata file will be created, and the file properties you want included.

var searchMeta = require('metalsmith-searchmeta');
      path: 'searchMeta.json',
      properties: ['title', 'date', 'author']   

This will generate a JSON file with metadata for every file included in the lunr search. The structure will be similar to the metalsmith file structure, with the file containing a single JSON object, with the urls being the keys, and the metadata being the values. For instance, the file might look like this:

         "title":"Page 1",
         "title":"Page 2",

On your search page, you can take the results returned by lunr, retrieve the file metadata and then display it using your client-side templating engine of choice.


You can use the plugin without supplying any options. If no options are supplied, the following defaults will be used:

   var defaults = { 
      path: 'searchMeta.json',
      properties: ['title', 'date', 'author', 'tags', 'image', 'wordCount', 'readingTime', 'path']

If these properties do not exist on your files, they will just be ignored.


$ npm test