-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (50 loc) · 1.15 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
const { marked } = require('marked')
function readyFileContent(fileName) {
return new Promise((resolve, reject) => {
const fs = require('fs');
fs.readFile(fileName, 'utf8', (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
function writeFile(html) {
return new Promise((resolve, reject) => {
const fs = require('fs');
fs.writeFile('build/index.html', html, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}
const getHtmlFromTemplate = (body) => {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>AIGC站点导航 - ChatGPT、New Bing、文心一言、Google Bard、Midjourney等</title>
<style>
a {
color: #58a6ff;
}
</style>
</head>
<body>
${body}
</body>
</html>`
}
readyFileContent('README.md').then((source) => {
const result = marked.parse(source);
const html = getHtmlFromTemplate(result)
writeFile(html);
})