forked from d33d33/warp10-tour
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundleLessons.js
41 lines (34 loc) · 1.02 KB
/
bundleLessons.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
var fs = require('fs'),
path = require('path'),
showdown = require('showdown');
showdown.setOption('noHeaderId', true);
showdown.setOption('headerLevelStart', 3);
showdown.setOption('tables', true);
var converter = new showdown.Converter();
var PATH = 'lessons',
lessons = [];
fs.readdirSync(PATH)
.sort()
.forEach(function (h) {
var p = path.join(PATH, h);
if (fs.statSync(p)
.isDirectory()) {
var lesson = {
title: h.split('_').slice(1).join(' '),
pages: []
};
fs.readdirSync(p)
.sort()
.forEach(function (f) {
var title = path.parse(f).name.split('_').slice(1).join(' '),
ctn = fs.readFileSync(path.join(p, f), 'utf8').split(/~{3,}/);
lesson.pages.push({
title: title,
content: converter.makeHtml(ctn[0].trim()),
einst: (ctn[1] || '').trim()
});
});
lessons.push(lesson);
}
});
fs.writeFileSync('lessons.js', 'window.LESSONS = ' + JSON.stringify(lessons));