Morgan Conrad

Metalsmith.io plugins

Metalsmith plugins


Metalsmith is a pluggable file processor, built on NodeJS, generally used for creating static web sites.


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 and test coverage compiled by Coveralls.


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'}));


metalsmith-get-contentful

Reads content from Contentful, places into metalsmith "files" for processing (e.g. by Markdown)

To grab all "projects", use their field "slug" as a filename, and put them under the path "/projects/{slug}.md"

.use(metalsmith-get-contentful({
   client: {
      space: '<space_id>',
      accessToken: '<access_token>'
   },
   query : {
      content_type: 'project'
   },
   msFiles : {
      idField: 'slug',
      filename: "projects/${id}.md"
   }
} ) )

Uses JavaScript nodejs NPM