-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (49 loc) · 1.42 KB
/
index.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
// @ts-check
import markdown from "markdown-it";
import { katex } from "@mdit/plugin-katex";
import prism from "markdown-it-prism";
import attrs from "markdown-it-attrs";
import anchor from "markdown-it-anchor";
import { readFile, writeFile, mkdir } from "node:fs/promises";
import path from "node:path";
const TITLE = "Mini-Lisp 语言规范";
const md = markdown({
html: true,
linkify: true,
breaks: true,
});
md.use(katex)
.use(prism)
.use(attrs)
.use(anchor, {
permalink: anchor.permalink.headerLink()
});
const SRC_PATH = "./README.md";
const DEST_PATH = "./dist/index.html";
const STYLES = [
"https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css",
"./prism.css",
"./latex.css",
"https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;700&family=Noto+Serif+SC:wght@400;700&display=swap",
"https://lalten.github.io/lmweb/style/latinmodern-roman.css",
"https://lalten.github.io/lmweb/style/latinmodern-mono.css",
];
const src = await readFile(SRC_PATH, "utf-8");
let dest = md.render(src, {});
dest = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>${TITLE}</title>
${STYLES.map(
(s) => `<link rel="stylesheet" href="${s}">`
).join("")}
</head>
<body>
<div id="container">
${dest}
</div>
</body>
</html>`;
await mkdir(path.dirname(DEST_PATH), { recursive: true });
await writeFile(DEST_PATH, dest, "utf-8");