-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprebuild.script.js
44 lines (34 loc) · 1.05 KB
/
prebuild.script.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
// @ts-check
import fs from "node:fs/promises";
import { marked } from "marked";
import assert from "node:assert";
const rmd = (await fs.readFile("README.md")).toString();
const lines = rmd.split("\n");
const start = lines.findIndex((l) => l.startsWith("## คาถาติดผู้แทน"));
const quotes_md = [];
const quotes_html = [];
for (let i = start + 1; i < lines.length; i++) {
if (lines[i].startsWith("##")) break;
if (!lines[i].startsWith("-")) continue;
const line = lines[i].slice(1).trim();
quotes_md.push(line);
quotes_html.push(
marked(line).replace(
/href="https:\/\//g,
"target='_blank' rel='noopener' href=\"https://"
)
);
assert(quotes_md.length == quotes_html.length);
}
await fs.writeFile(
"src/คาถาผู้แทน.md.g.json",
JSON.stringify(quotes_md, null, 2)
);
await fs.writeFile(
"src/คาถาผู้แทน.html.g.json",
JSON.stringify(quotes_html, null, 2)
);
await fs.writeFile(
"tests/test_helper.g.js",
`export const quotes_length = ${quotes_md.length};`
);