-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk_html.js
89 lines (83 loc) · 2.13 KB
/
mk_html.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const fs = require('fs'),
path = require('path'),
cli_table = require('table').table,
AU = require('ansi_up'),
ansi_up = new AU.default,
{display_data, get_corona_data, graphs, map, select, shader} = require('./corona');
const html = (nav, [us_map, graphs, table], states) => `<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>USA Corona Tracker</title>
<meta name='date' content='${new Date().toLocaleDateString()}'>
<link rel="stylesheet" href="./style.css">
<style>
html, a, pre {
background: #2B2B2b;
color: #f8f8f8;
font-family: FreeMono, monospace;
}
pre {
margin: 0;
letter-spacing: -1px;
}
h1 {
margin: 0 10px;
}
td {
vertical-align: top;
}
</style>
</head>
<body>
<h1>USA Corona Tracker</h1>
<table>
<tr>
<td>
<pre>
${nav}
</pre>
</td>
<td>
<a id="usa"></a>
<pre>
${us_map}
${graphs}
${table}
</pre>
${states.join('\n')}
</td>
</tr>
</table>
</body>
</html>`;
const id = s => s.replace(/\s+/g, '-').toLowerCase();
(async () => {
const data = await get_corona_data(),
states = [...new Set(data.deaths.map(({Province_State}) => Province_State))].sort(),
to_display = select(data),
shade = shader(to_display[1].Deaths),
nav_entries = ['USA'].concat(states);
let nav = cli_table([
['Nav'],
[nav_entries.join('\n')],
]);
nav_entries.forEach(s => {
nav = nav.replace(s, `<a href="#${id(s)}">${s}</a>`);
});
const index = html(
nav,
[
map(data, shade),
graphs(data),
display_data(to_display, true),
].map(s => ansi_up.ansi_to_html(s)),
states.map(s => [
`<h2 id="${id(s)}">${s}</h2>`,
`<pre>${ansi_up.ansi_to_html(graphs(data, s))}</pre>`,
`<pre>${ansi_up.ansi_to_html(display_data(select(data, s), true))}</pre>`,
].join('\n')),
);
fs.writeFileSync(path.join(__dirname, 'index.html'), index);
})();