1.0.0 • Published 10 years ago

metalsmith-hogan v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

metalsmith-hogan

A metalsmith plugin to render templates using hogan.js, supports partials

var Metalsmith = require('metalsmith')
var templates = require('metalsmith-hogan')

Metalsmith(__dirname)
  .use(templates())
  .build();

options:

  • path - templates folder path, relative to metalsmith root path - default: templates
  • extensions - file extension that should be read as templates - default: '.html', '.hbt', '.hb'
  • filter - a filter function ran before each file source template compilation, useful to add custom data based on the file source

Filter example

Add an 'is-active' class to the menu item, if it matches the link property

var menu = [{
  label: 'Home'
, link: 'index.html'
}, {
  label: 'About'
, link: 'about.html'
}]

function setNavigation (filepath, data, templates) {
  data.menu.forEach(function (item) {
    item.class = (path == item.link) ? 'is-active' : null
  })
}

Metalsmith(__dirname)
  .metadata({ menu: menu })
  .use(templates({
    filter: setNavigation
  }))
  .build();

Template:

<ul>
  {{# menu }}
    <li class="{{ class }}">{{ label }}</li>
  {{/ menu }}
</ul>

License MIT