-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender-talks.js
executable file
·58 lines (49 loc) · 1.63 KB
/
render-talks.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
const fs = require('fs');
const talks = fs.readdirSync("talks").filter(file => file.match(/(.*\.(adoc))/ig)).map(file => "talks/" + file);
const asciidoctor = require('asciidoctor.js')();
const asciidoctorRevealjs = require('asciidoctor-reveal.js');
asciidoctorRevealjs.register()
const asciidoctorPlantuml = require('asciidoctor-plantuml');
asciidoctorPlantuml.register(asciidoctor.Extensions);
const registry = asciidoctor.Extensions.create();
asciidoctorPlantuml.register(registry);
const renderOptions = { safe: 'safe', backend: 'revealjs', extension_registry: registry };
renderAllTalks()
if (process.argv[2] == "watch") {
watchAndRenderContinuous()
}
function renderAllTalks() {
talks.forEach(talk => render(talk));
}
function render(talk) {
console.log(Date() + " - Rendering " + talk);
asciidoctor.convertFile(talk, renderOptions);
let html = talk.split(".adoc")[0] + ".html";
fs.renameSync(html, html.split("/")[1]);
}
function watchAndRenderContinuous() {
let fsWait = false;
talks.forEach(talk => {
console.log("Watching: " + talk)
fs.watch(talk, (e, f) => {
if (fsWait) {
return;
} else {
fsWait = setTimeout(() => {
fsWait = false;
}, 250);
render(talk);
}
});
});
fs.watch("talks/_theme", (e, f) => {
if (fsWait) {
return;
} else {
fsWait = setTimeout(() => {
fsWait = false;
}, 250);
renderAllTalks();
}
});
}