Here is a basic Metalsmith example:
Code: Select all
var Metalsmith = require('metalsmith');
var markdown = require('metalsmith-markdown');
Metalsmith(__dirname)
.source('./src')
.destination('./build')
.use(markdown())
.build(function(err) {
if (err) throw err;
});
Writing plugins for Metalsmith is quite simple; You create a function with 3 arguments (files, metalsmith, done), and register the function with a call to .use(). Here is a basic plugin, it just loop through all the loaded files and transforms their contents:
Code: Select all
function(files, metalsmith, done) {
for (var i = 0; i < files.length; i++) {
var fileName = files[i];
var file = files[fileName];
var content = file.content;
// Transform content here.
file.content = content;
}
done();
}