forked from mario206/qqsrx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergeTxt.js
77 lines (53 loc) · 1.43 KB
/
mergeTxt.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const fs = require('fs');
const path = require('path');
const glob = require('glob')
const Epub = require("epub-gen");
const main = async () => {
console.log("main start")
var output = "./锵锵三人行.txt"
if(fs.existsSync(output)) {
fs.unlinkSync(output)
}
const files = glob.sync("./**/*.txt")
files.sort()
console.log("files count: " + files.length)
var content = ""
var epubContents = []
var mdDir = "./md";
if(!fs.existsSync(mdDir)) {
fs.mkdirSync(mdDir);
}
files.forEach((file)=>{
var name = path.parse(file).name
var str = fs.readFileSync(file,'utf8')
var dst = []
var lines = str.split('\n');
lines = lines.splice(1);
lines.forEach(line=>{
var isMatch = /说话人 \d .*/g.exec(line)
if(!isMatch) {
dst.push(line)
}
})
var str = dst.join('\n')
str = "## " + name + "\n" + str;
var epubData = ""
dst.forEach(line=>{
epubData += `<p>${line}</p>`
})
content += str;
fs.writeFileSync(`./${mdDir}/${name}.md`,str,{flag:"w"})
epubContents.push({title:name,author:"",data:epubData})
})
fs.writeFileSync(output,content);
const option = {
title: "锵锵三人行",
author: "",
publisher: "",
cover: "", // Url or File path, both ok.
content: epubContents
};
//new Epub(option, "./锵锵三人行.epub");
console.log("main end")
};
main().catch((err) => console.error(err));