-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
38 lines (31 loc) · 936 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var extend = require('extend')
var fs = require('fs')
var Handlebars = require('handlebars')
module.exports = plugin
function plugin (options) {
options = extend({
directory: 'helpers'
}, options || {})
return function (files, metalsmith, done) {
fs.readdir(metalsmith.path(options.directory), function (err, files) {
if (err) throw err
files.forEach(function (file) {
var helperContents
var path
var templateName
path = metalsmith.path(options.directory, file)
helperContents = require(path)
switch (typeof helperContents) {
case 'function':
templateName = helperContents.name || file.split('.').shift()
Handlebars.registerHelper(templateName, helperContents)
break
case 'object':
Handlebars.registerHelper(helperContents)
break
}
})
done()
})
}
}