Metalsmith for masses

You can’t have missed that static site generators is one of the buzzwords these days. If you google for it, you’ll find that you have a ton of options in a ton of languages.

Since I recently moved my blog from Drupal to Metalsmith, I’ll write some posts to explain the process and get some insight on the internals of this tool.

I won’t explain why I choosed to move from Drupal, which is indeed a good CMS, because it’s easy to find posts explaining the case of static site generators. But why Metalsmith then ?

  • It’s written in javascript and runs in node.js, which are my current main points of interest.
  • It’s simple. Actually, metalsmith itself is about 200 lines of code.
  • I think the official web site is very elegant (hey, being a developer doesn’t mean being esthetically impaired, not always at least)

Let’s talk a bit more about its supposed simplicity.

Really simple ?

Metalsmith describes itself as an extremely simple, pluggable static site generator. In fact, it does very little by itself, but relies on the plugins to do the heavy lifting, hence the small code base.

To paraphrase the official site, Metalsmith works with three simple steps:

  1. Read all the files in a source directory.
  2. Invoke a series of plugins that manipulate the files.
  3. Write the results to a destination directory !

As you can see on this diagram, all the computing and modifications are done by the plugins. Without plugin, your destination directory will be the same than the source one.

What are the available plugins

The official site maintains a growing list of plugins. In bulk you’ll find for example:

  • file transformation plugins (markdown, rho, less, sass, coffee, …)
  • file metadata manipulation (except, headings, more, …)
  • file list manipulation (drafts, copy, fingerprint, …)
  • build process plugins (uglify, webpack, watch, gulpsmith, assets, …)
  • templating plugins (templates, jade, …)
  • external services invocation plugins (gravatar, contentful, …)
  • and many more…

Yeah, I also think we could use some categorizing now.

Considering the explosion of the plugins number, it’s very likely that you’ll find most of what you need. And if you search github for the keyword ‘metalsmith’, you’ll find a number of plugins which have not (yet ?) been submitted to the metalsmith team.
But the best part is the easiness with which you can write your own plugins, in case you really need it.

Other resources

You’d like to read more about Metalsmith before making your choice ?

First, you should read what has to say, since it will give you a global view of the tool (and it’s elegant). But you already did it, didn’t you ?

If you’re a developer, you should also get the metalsmith project on github and check the examples. Since you’re on github now, try to see what plugins are available by searching the “metalsmith” keyword. Even if they’re easy to write, as you will know soon, using an existing plugin is even easier !

Finally, I recommend you to read the excellent posts on Metalsmith by Robin Thrift. They really helped me to begin understanding this nice tool.

In my next post, I’ll expand our knowledge about the way Metalsmith processes these files and we’ll build a simple logging plugin to understand what happens.

comments powered by Disqus