-
Notifications
You must be signed in to change notification settings - Fork 0
/
indico-timetable2html.js
64 lines (56 loc) · 2.36 KB
/
indico-timetable2html.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
61
62
63
64
const agh = require("agh.sprintf");
const baseurl = process.env.indico_baseurl;
const inputFile = process.env.indico_input;
function htescape(s) {return s.replace(/[&<>]/g, $0 => {return {"&": "&", "<": "<", ">": ">"}[$0];});}
function atescape(s) {return s.replace(/[&<>"]/g, $0 => {return {"&": "&", "<": "<", ">": ">", "\"": """}[$0];});}
console.log("<!DOTYPE html>");
console.log("<html>");
console.log("<head>");
console.log(" <link rel=\"stylesheet\" href=\"slides.css\" />");
console.log(" <script src=\"slides.js\"></script>");
console.log(" <title>QM2022 Contributions & Slides</title>");
console.log("</head>");
console.log("<body>");
console.log("<h1>QM2022 Contributions & Slides</h1>");
let current_date = "";
let session_name = "";
let session_index = 0;
let talk_index = 0;
const fs = require("fs");
JSON.parse(fs.readFileSync(inputFile, "utf8")).forEach(talk => {
if (current_date != talk.date) {
current_date = talk.date;
session_index = 0;
}
if (session_name != talk.session) {
console.log("");
session_name = talk.session;
session_index++;
talk_index = 0;
console.log("<h2>" + htescape(session_name) + "</h2>");
}
talk_index++;
console.log("<div class=\"talk\">");
console.log(" <h3 class=\"talk\">");
if (talk.attach) {
let attach_index = 0;
talk.attach.forEach(link => {
if (link.startsWith("/")) link = baseurl + link;
const name = link.replace(/^.*\//, "");
const file = agh.sprintf("%s-S%02d%02d%s-%s", talk.date, session_index, talk_index, "abcdefghijklmnop".substr(attach_index++, 1), name);
const ext = /[^.]+\.[^.]+$/.test(name) ? name.replace(/^.*\./, "").toLowerCase() : null;
console.log(" <a class=\"attach" + (ext ? " type-" + ext : "") + "\" title=\"" + atescape(link) + "\" href=\"" + atescape(file) +"\">[" + htescape(ext || name) + "]</a>");
console.log(" <!-- DOWNLOAD \"" + link + "\" \"" + file + "\" -->");
});
}
console.log(" <span class=\"author\">" + htescape(talk.author || "?????") + "</span>");
console.log(" <span class=\"title\">" + htescape(talk.title) + "</span>");
console.log(" </h3>");
if (talk.desc) {
console.log(" <span class=\"desc\">" + htescape(talk.desc).replace(/\r?\n/g, "<br/>") + "</span>");
}
console.log("</div>");
});
console.log("");
console.log("</body>");
console.log("</html>");