# metalsmith-hooks

> A Metalsmith plugin to add arbitrary hooks to your build.

Latest version **0.1.1** (published 2017-08-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install metalsmith-hooks
pnpm add metalsmith-hooks
yarn add metalsmith-hooks
bun add metalsmith-hooks
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-08-26 |
| First published | 2017-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Ben Wilhelm |
| Maintainers | benwilhelm |

## Links

- npm: https://www.npmjs.com/package/metalsmith-hooks
- Repository: https://github.com/benwilhelm/metalsmith-hooks
- Homepage: https://github.com/benwilhelm/metalsmith-hooks#readme
- Issues: https://github.com/benwilhelm/metalsmith-hooks/issues
- npm.io page: https://npm.io/package/metalsmith-hooks

## Dependencies (2)

- [async](https://npm.io/package/async.md) ^2.5.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4

## Recent versions

- 0.1.1 (latest) — 2017-08-26
- 0.1.0 — 2017-08-23

## README

![travis build](https://travis-ci.org/benwilhelm/metalsmith-hooks.svg?branch=master)

[![Coverage Status](https://coveralls.io/repos/github/benwilhelm/metalsmith-hooks/badge.svg)](https://coveralls.io/github/benwilhelm/metalsmith-hooks)

# metalsmith-hooks

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

## Usage

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.

```javascript
// index.js

metalsmith(__dirname)
.metadata({
  title: "My cool site"
})
.source('./src')            
.destination('./build')     
//...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 <name-of-page> is the index that metalsmith uses to track the page, such as
`about-us.md`.

```javascript
// hooks/pre-build/about-us.md.js

/**
 * 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.

---
_Source: https://npm.io/package/metalsmith-hooks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
