forked from xiaoyu2er/xwlb
-
Notifications
You must be signed in to change notification settings - Fork 3
/
readme.js
63 lines (56 loc) · 1.44 KB
/
readme.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
const fs = require("fs");
const showdown = require("showdown");
const converter = new showdown.Converter();
function update() {
var files = fs.readdirSync("./news").reverse();
var htmlFiles = fs.readdirSync("./html").reverse();
console.log(files);
var news = files.map((f) => `+ [${f.replace(".md", "")}](./news/${f})`);
var newsHtml = htmlFiles.map(
(f) => `+ [${f.replace(".html", "")}](https://raw.githubusercontent.com/landv/xwlb/master/html/${f})`
);
var str = `# 新闻联播
## 如何使用
\`\`\`bash
node index.js 2021-06-20 2021-06-30
\`\`\`
## 新闻列表
${news.join("\n")}
`;
const htmlContent = converter.makeHtml(`
${newsHtml.join("\n")}
`);
const html = `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>新闻联播</title>
</head>
<body>
${htmlContent}
</body>
</html>
`;
fs.writeFileSync("./README.md", str);
fs.writeFileSync("./README.html", html);
}
function rename() {
var files = fs.readdirSync("./news");
files.forEach((f) => {
var dest = f.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3");
// console.log(f, dest);
fs.renameSync(`./news/${f}`, `./news/${dest}`);
});
}
module.exports = {
update,
};
if (!module.parent) {
// this is the main module
// rename();
update();
} else {
// we were require()d from somewhere else
}