Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

travis build

Coverage Status


A metalsmith plugin for adding page-specific hooks to your build

This plugin allows you to add page-specific hooks to your metalsmith build at arbitrary points. Think of them as per-page plugins


npm install metalsmith-hooks


First, add the hooks plugin to the point in your build that you'd like to hook into. If you want to add it in multiple places, define the stage option for each one.

// index.js

let metalsmith = require('metalsmith');
let hooks = require('metalsmith-hooks');

  title: "My cool site"
//...other stuff
.use(hooks({          // defines the point in the build process
  stage: 'pre-build'  // where you'd like to run your hooks
.build(function(err) {      
  if (err) throw err;       

Then, in the hooks/<stage> directory, place a file called <name-of-page>.js, where <stage> is the stage name of the stage you defined in the previous file, and is the index that metalsmith uses to track the page, such as

// hooks/pre-build/

 * Here you can do some processing on the individual page. Notice that the
 * function signature is very similar to a metalsmith plugin, but the first
 * argument is a single page, not the dictionary of pages.
module.exports = function(page, metalsmith, done) {

Plugin options

The options hash takes the following params:

  • directory (optional) - The directory (relative to project root) in which place your hooks. Defaults to /hooks
  • stage (required if using in multiple places) - An arbitrary name for the point in your build that the hooks are running. The app will look for the individual hook files in that directory. If not defined, it will look in the top level of the hooks directory.


A metalsmith plugin for adding page-specific hooks to your build




No packages published
You can’t perform that action at this time.