-
Notifications
You must be signed in to change notification settings - Fork 27
/
page-build.js
40 lines (30 loc) · 994 Bytes
/
page-build.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
'use strict';
let handlebars = require('handlebars');
let layouts = require('handlebars-layouts');
let fs = require('fs');
let path = require('path');
let mkdirp = require('mkdirp');
let input = path.join(__dirname, '../views/views-content');
let pageFiles = fs.readdirSync(input);
let output = path.join(__dirname, '../views');
let layoutPath = path.join(__dirname, '../views/layouts/layout.hbs');
// Register helpers
handlebars.registerHelper(layouts(handlebars));
// Register partials
handlebars.registerPartial('layout', fs.readFileSync(layoutPath, 'utf8'));
function buildPages(files) {
files.forEach((file) => {
let HTMLPath = path.join(__dirname, `../views/views-content/${file}`);
// Compile template
let template = handlebars.compile(fs.readFileSync(HTMLPath, 'utf8'));
// Render template
let render = template();
fs.writeFileSync(path.join(output, file), render);
});
}
function start() {
buildPages(pageFiles);
}
module.exports = {
start
};