Extracting Libs from a Node.js Project

Publishing my Metalsmith Plugins

· by Mario Ranftl · 344 words, 2 min ·  javascript  programming

As promised, lets break out my customized plugins I’ve used with metalsmith to build up this site. I had to rename them (see this pull request) in order to be allowed to publish them on metalsmith.io.

I’ve published these plugins:

How to extract logic into standalone packages

Before publishing, my custom metalsmith plugins lived in their respective metalsmith-XXX.js file within the same project directory. I simply required them in my index.js file. Now I’m moving them into their own package, so they can be reused in the future. Here’s a quick overview on how to do that:

  1. The first step was to set up a new package for each plugin.
  2. npm init to get a proper one and install all dependent packages that you will need in the plugin.
  3. Copy over all the code and point the main field in your package.json to the proper file. Attention, don’t forget do install all required dependencies!
  4. npm link your new package to temporary locally use it within your root project.
  5. Test and finally publish it.


Are you curious about how the word count and estimated reading time are computed on my site? It’s done via my plugin metalsmith-word-count. It calculates the wordcount and average reading time of all paragraphs in a HTML file.

install from npm · source on github


Do you want to automatically turn your markdown headings (h1-h6) into clickable permalinks? Then grab metalsmith-headings-identifier. This idea is originally by Remy Sharp, with the difference, that it’s now done during generation time with metalsmith.

headingsidentifier example picture

install from npm · source on github


Inspired by Paul Irish’s work to use markdown within HTML tags, here comes “something similar” (not as sophisticated) wrapped in a metalsmith plugin. Now you can use data-markdown attributes to identify tags, that wrap markdown content and need to be converted to HTML during generation time.

install from npm · source on github

Further reading

  About the author

Mario Ranftl is a dedi­cated Aus­trian senior soft­ware en­gi­neer with con­sider­able ex­peri­ence in a range of soft­ware develop­ment en­viron­ments and a special­ization in web tech­nologies. He con­trib­utes to Open Source pro­jects on GitHub and loves to cre­atively solve chal­lenging prob­lems. You can easily reach him via Email.

  Share and subscribe

  Related notes

Hello World