Adventures with Metalsmith
On the advice of a wise and experienced friend, I started looking into static site generators. I wanted to create a new portfolio site and integrate it with my blog, which I was ready to move off of Tumblr.
Having used Drupal for several years, I was both puzzled and intrigued by this concept. What --- no database to store our content?? How will we be able to separate our content into semantically appropriate chunks that can later be reassembled? Are there any security risks? Does this provide benefits performance-wise?
In the end, I decided to go this route because I couldn’t face either (1) creating a DB seed file with my old blog posts, or (2) re-entering all of my blog posts either manually or into a DB GUI.
A static site generator that read both markdown and HTML seemed like an efficient way to go -- just export my old posts as CSVs, cut them into separate files, and -- abracadabra -- new site!
I was attracted to Metalsmith because it advertised itself as built on NodeJS and being friendly to JS developers. Yeah, I can do that!
However, my first encounters with Metalsmith were like an awkward first date.
Awkward moment #1: build files output as .html
Oof! I feel like I’ve been caught with a giant pimple on my nose. I haven’t had a site with .html pages since... well probably about 2008. Needing to get the site up quickly, though, I’ll have to set aside this blemish for later cleanup.
Awkward moment #2: the documentation
I would love to help the author(s) add a bit more documentation. Metalsmith is billed as “simple”, but the labyrinth of Readme files and links on GitHub are a bit of a puzzle. When trying something for the first time, I learn best by looking at completed examples, rather than by trying to assemble a bunch of disconnected code snippets on multiple pages. Some of the linked blog entries are super helpful, but ideally this should be contained in the core documentation.
Awkward moment #3: collections
I couldn’t get file-path pattern-matching working for collections to my satisfaction. I wanted to create two separate collections, "blogposts” and “projects”. You’re supposed to be able via use.collections(blogposts: {pattern: ‘somedirectory/*.md’}) in your build file, but I couldn’t get that to produce actual collections.
I tried creating a ‘superset’ collection for all articles: .use(collections({ articles: {pattern: '*/*.*'}}))
but this also picks up my ‘index’ pages.
For blog posts and projects, I ended up labeling each .md file as belonging to a particular Collection within the front matter, just to save time in the short term.
No big deal for my small site, but I would love to figure out how to use this properly.
Awkward moment #5: sorting collections by date
This was admittedly a beginner’s mistake :-) If you want to sort a collection by date in ascending order, do NOT use a key-value pair “reverse: ‘false’“. It doesn’t exist! Just use the following:
` .use(collections({ blogposts: { sortBy: 'date', reverse: 'true' }, projects: { sortBy: 'date' }
}) ` I have a lot more work to do before my experiment is ready for prime time, but it was interesting learning a l little about static site generators!







