-
Notifications
You must be signed in to change notification settings - Fork 0
/
metalsmith.js
executable file
·67 lines (61 loc) · 1.81 KB
/
metalsmith.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const metalsmith = require('metalsmith');
const define = require('metalsmith-define');
const markdown = require('metalsmith-markdown');
const layouts = require('metalsmith-layouts');
const inplace = require('metalsmith-in-place');
const watch = require('metalsmith-watch');
const handlebars = require('handlebars');
const filenames = require('metalsmith-filenames');
const handlebarsLayouts = require('handlebars-layouts');
const serve = require('metalsmith-serve');
const assets = require('metalsmith-assets');
const config = require('./metalsmith.config');
const dev = ((process.env.NODE_ENV || '').trim().toLowerCase() !== 'production');
handlebars.registerHelper(handlebarsLayouts(handlebars));
const ms = metalsmith(__dirname)
.clean(true)
.source(config.src.content)
.use(filenames())
.use(define({
development: dev ? true : null,
}))
.use(markdown({
smartypants: true,
gfm: true,
tables: true,
}))
.use((files, metalsmith, next) => {
var content;
var k;
var regex = new RegExp('{{>', 'g');
for (k in files) {
content = files[k].contents.toString();
files[k].contents = new Buffer(content.replace(regex, '{{>'));
}
next();
})
.use(inplace({
engine: 'handlebars',
partials: config.src.partials,
pattern: '*.html',
}))
.use(layouts({
engine: 'handlebars',
directory: config.src.layout,
partials: config.src.partials,
}))
.use(assets({
source: config.src.assets,
destination: config.dist.assets,
}))
.destination(config.dist.html);
if (dev) {
ms.use(watch({
paths: config.src.watch,
livereload: true,
}))
.use(serve(config));
}
ms.build((err) => {
if (err) throw err;
});