-
Notifications
You must be signed in to change notification settings - Fork 3
/
generateDocs.js
38 lines (34 loc) · 1005 Bytes
/
generateDocs.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
const ejs = require("ejs");
const fs = require("fs").promises;
Promise.all([
fs.readFile("docs/casesPerDay.json"),
fs.readFile("docs/casesPerCounty.json"),
]).then(([casesPerDayString, casesPerCountyString]) => {
let casesPerDay = JSON.parse(casesPerDayString);
let casesPerCounty = JSON.parse(casesPerCountyString);
let cases = casesPerDay.map((x) => x.cases).reduce((a, b) => Math.max(a, b));
let recovered = casesPerDay
.map((x) => x.recovered)
.reduce((a, b) => Math.max(a, b));
let died = casesPerDay.map((x) => x.died).reduce((a, b) => Math.max(a, b));
let dtf = new Intl.DateTimeFormat("hr", {
year: "numeric",
month: "long",
day: "2-digit",
});
ejs.renderFile(
"template.html",
{
cases,
recovered,
died,
lastUpdated: dtf.format(new Date()),
casesPerCounty: Object.entries(casesPerCounty),
},
async (err, str) => {
if (!err) {
await fs.writeFile("docs/index.html", str);
}
}
);
});