metalsmith-transform
Transform or manipulate file objects in the metalsmith pipeline

About
metalsmith-transform
is a metalsmith plugin which allows the use of custom functions to manipulate the file object in a metalsmith pipeline.
Furthermore, instead of writing a full plugin, you can just pass in the transformation function into this instead.
String methods are inspired by gulp-insert.
Installation
$ npm install metalsmith-transform
or
$ yarn add metalsmith-transform
Usage
API
import transform from 'metalsmith-transform';
You can pass in an object or a function as an argument. i.e.
metalsmith.use(transform(function(fileObject, metalsmithData) {
return fileObject;
}));
metalsmith.use(transform({
action: '',
value: '',
pattern: '*.md'
}));
CLI
"plugins": {
"metalsmith-transform": {
"action": "append",
"value": "Include Me!"
}
}
Note on CLI Usage: Since JSON does not take functions, only append
, prepend
and wrap
actions are accepted.
Available Actions
By default, if an action is not defined, append
is used.
In the examples below, assume that the content in your files are "I am".
Transform
Calls a function with the file
object and metalsmith
instance.
Function should return the modified contents of the file.
metalsmith.use(transform(function(data, m){
let contents = data.contents.toString().toUpperCase();
data.contents = new Buffer(contents);
return data;
}));
Append
Appends a string onto the contents.
metalsmith.use(transform({
action: 'append',
value: 'world'
}));
Prepend
Prepends a string onto the contents.
metalsmith.use(transform({
action: 'prepend',
value: 'hello'
}));
Wrap
Wraps the contents with two strings.
metalsmith.use(transform({
action: 'wrap',
value: ['hello', 'world']
}));
License
metalsmith-transform
is MIT licensed