提交 b2fbe0a7 编写于 作者: W wizardforcel

2019-06-27 00:03:05

上级 e3fb2593
......@@ -15,9 +15,11 @@ function fnameEscape(name){
return name.replace(/\\|\/|:|\*|\?|"|<|>|\|/g, '-')
}
function writeEpub(articles, imgs, bookName) {
function writeEpub(articles, imgs, name, path) {
bookName = fnameEscape(bookName || articles[0].title)
name = name || articles[0].title
path = path || fnameEscape(name) + '.epub'
if(!path.endsWith('.epub')) path += '.epub'
var zip = new jszip();
zip.file('mimetype', fs.readFileSync(d('./assets/mimetype')));
......@@ -53,7 +55,7 @@ function writeEpub(articles, imgs, bookName) {
imgToc: imgToc,
htmlToc: htmlToc,
uuid: uuid,
name: bookName,
name: name,
});
zip.file('OEBPS/content.opf', opf);
......@@ -63,7 +65,8 @@ function writeEpub(articles, imgs, bookName) {
});
zip.file('OEBPS/toc.ncx', ncx);
zip.generateAsync({type: 'nodebuffer', 'compression':'DEFLATE'}).then(co => fs.writeFileSync(`${bookName}.epub`, co))
zip.generateAsync({type: 'nodebuffer', 'compression':'DEFLATE'})
.then(co => fs.writeFileSync(path, co))
}
module.exports = writeEpub
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册