-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
50 lines (46 loc) · 1.26 KB
/
index.mjs
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
import { readdir, writeFile } from "fs/promises";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
function render(files) {
const links = files
.map(
(file) =>
`<li><a href="./${file}.html" target="_blank">${file}</a> (<a href="./${file}.pdf" target="_blank">PDF</a>)</li>`
)
.join("\n");
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UCSC CSE 130 Spring 2023</title>
<link rel="stylesheet" href="https://fonts.xz.style/serve/inter.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@exampledev/[email protected]/new.min.css">
</head>
<body>
<header>
<h1>UCSC CSE 130</h1>
</header>
<ul>
${links}
</ul>
</body>
</html>
`;
}
async function main() {
const files = await readdir(join(__dirname, "slides"));
const f = [];
for (const file of files) {
if (file.endsWith("md")) {
f.push(file.split(".")[0]);
}
}
f.sort();
const data = new Uint8Array(Buffer.from(render(f)));
await writeFile(join(__dirname, "public", "index.html"), data);
}
main();