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]))
- return (or callback with) either an Object or an Array (see options.id)
- if there is an err
files
will remain unchanged
- 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