-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
60 lines (51 loc) · 1.8 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// imports
const path = require("path");
const marked = require('marked');
const fs = require('fs');
const ejs = require("ejs");
// directories
const publicDir = path.join(__dirname, "public");
const pagesDir = path.join(__dirname, "pages");
const mdDir = path.join(__dirname, "text");
// markdown
function mdToHtml(fileName) {
const dir = path.join(mdDir, fileName + ".md");
const text = fs.readFileSync(dir, {"encoding" : "utf8"});
const html = {"content" : marked(text)}
return html;
}
const music = mdToHtml("explain-music")
const code = mdToHtml("explain-code")
const inst = mdToHtml("instructions")
const about = mdToHtml("about")
// render
ejs.renderFile(path.join(pagesDir, "sketch.ejs")).then(value => {
fs.writeFileSync(path.join(publicDir, "index.html"), value)
}, reason => {
console.error("RENDER ERROR:" + reason)
})
ejs.renderFile(path.join(pagesDir, "text.ejs"), music).then(value => {
fs.writeFileSync(path.join(publicDir, "explain-music.html"), value)
}, reason => {
console.error("RENDER ERROR:" + reason)
});
ejs.renderFile(path.join(pagesDir, "text.ejs"), code).then(value => {
fs.writeFileSync(path.join(publicDir, "explain-code.html"), value)
}, reason => {
console.error("RENDER ERROR:" + reason)
});
ejs.renderFile(path.join(pagesDir, "text.ejs"), inst).then(value => {
fs.writeFileSync(path.join(publicDir, "instructions.html"), value)
}, reason => {
console.error("RENDER ERROR:" + reason)
});
ejs.renderFile(path.join(pagesDir, "text.ejs"), about).then(value => {
fs.writeFileSync(path.join(publicDir, "about.html"), value)
}, reason => {
console.error("RENDER ERROR:" + reason)
});
ejs.renderFile(path.join(pagesDir, "404.ejs"), about).then(value => {
fs.writeFileSync(path.join(publicDir, "404.html"), value)
}, reason => {
console.error("RENDER ERROR:" + reason)
});