-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (51 loc) · 1.81 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var Metalsmith = require('metalsmith'),
markdown = require('metalsmith-markdown'),
collections = require('metalsmith-collections'),
permalinks = require('metalsmith-permalinks'),
layouts = require('metalsmith-layouts'),
glob = require('glob'),
Handlebars = require('handlebars'),
HandlebarsIntl = require('handlebars-intl'),
ignore = require('metalsmith-ignore'),
fs = require('fs'),
metadata = require('./config')(process.argv),
moment = require('moment'),
date = require('metalsmith-build-date'),
hljs = require('highlight.js');
HandlebarsIntl.registerWith(Handlebars);
Handlebars.registerPartial('header', fs.readFileSync(__dirname + '/layouts/partials/header.hbt').toString());
Handlebars.registerPartial('footer', fs.readFileSync(__dirname + '/layouts/partials/footer.hbt').toString());
Handlebars.registerHelper('link', function(path) {
return metadata.baseUrl + path;
});
Handlebars.registerHelper('date', function(date) {
return moment(date).format('Do MMMM YYYY');
});
Metalsmith(__dirname)
.use(ignore('src/stylesheets'))
.use(collections({
pages: {
pattern: 'pages/*.md'
},
posts: {
pattern: 'posts/*.md',
sortBy: 'date',
reverse: true
}
}))
.use(markdown({
gfm: true,
tables: true,
smartLists: true,
smartypants: true,
highlight: function (code, lang, callback) {
return hljs.highlightAuto(code).value
}
}))
.use(permalinks({
pattern: ':collection/:title',
relative: true
}))
.use(layouts('handlebars'))
.destination('./dist')
.build(function (err) { if(err) console.log(err) })