/metalsmith-functional

Primary LanguageJavaScriptMIT LicenseMIT

Build Status License NPM Downloads Known Vulnerabilities Coverage Status

metalsmith-functional

Inspired by This feature request

Most metalsmith plugins directly modify the files object. There is a growing trend towards "functional style" or immutable code, which returns a new version of the object instead of modifying it. Until metalsmith supports this style, you can try using this plugin.

const functional = require('metalsmith-functional');
  ...
.use(functional(fn [,options]))
  

fn - your function, of the form fn(files, metalsmith [,callback(err, results)])

  • return (or callback with) either an Object or an Array (see options.id)
  • if there is an err files will remain unchanged

options

  • options.retain Do not delete existing key/value pairs in files. (default = false)
  • options.id if fn returns an array, which key to use for the filename is files