-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (45 loc) · 1.3 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 console = require("console")
var extend = require("xtend")
var fs = require("fs")
var minify = require("html-minifier").minify
var mkdirp = require("mkdirp")
var ncp = require("ncp")
var path = require("path")
var render = require("string-template")
var rmdir = require("rmdir")
var layoutData = require("./lib/layout-data")
var pageData = require("./lib/page-data")
var template = require("./lib/template")
var content = require("./lib/content")
var config = require("./config.json")
var layout = template("layout.html")
var outDir = path.join(__dirname, config.paths.output)
debugger;
fs.exists(outDir, function (exists) {
if (exists) {
rmdir(outDir, makeOutput)
} else {
makeOutput()
}
})
function makeOutput(err) {
if (err) {
return console.log(err)
}
mkdirp(outDir, generateSite)
}
function generateSite(err) {
if (err) {
return console.log(err)
}
// Generate the pages
content.forEach(function (page) {
var html = render(layout, extend(layoutData, pageData[page.type](page)))
fs.writeFile(path.join(outDir, page.output), minify(html, {
removeComments: true,
collapseWhitespace: true
}))
})
// Copy the site resources to the output directory
ncp(config.paths.resources, outDir)
}