metalsmith
Metalsmith plugins
Metalsmith is a pluggable file processor, built on NodeJS, generally used for creating static web sites.
- Reads files from a directory, extracts their information (typically using YAML) into a JS Object
- Processes these objects with plugins
- (typically Markdown for the content and a template language like Handlebars or JADE to generate the HTML)
- Writes the results to a destination directory.
The Metalsmith documentation is sparse, so I ended up writing a couple of plugins for debugging: assert and inspect. In developing them, it inspired two others: cp-r and keymaster.
All these modules are open-source, in JavaScript, available on NPM and GitHub, and use Tape for unit tests. CI is performed by Travis CI
metalsmith-assert
Test file objects with Node's assert module. For example, to test that all have a property named "title":
.use(metalsmith-assert({
"title exists" : { actual: "title"}
} ) )
metalsmith-cp-r
Copies a folder recursively, typically to copy web assets (CSS, scripts, images) from the working directory into the metalsmith destination directory. e.g.:
.use(metalsmith-cp-r({
from: "_directory/pathto/assets",
to: "_destination/pathto/assets"
} ) )
metalsmith-inspect
Inspects the file objects, typically via Node's util.inspect(). To see everything:
.use(metalsmith-inspect({}))
metalsmith-keymaster
A relatively simple but powerful plugin to create new values and store them under new keys. Since that's what most plugins do, this could be considered as a "meta-plugin" for developing plugins.
For example, to add the filename as metadata under the "foo" key:
.use(keymaster({from: function(data, filePath) {
return filePath;
},
to: 'foo'}));