提交 f60a46d9 编写于 作者: W wizardforcel

2020-07-23 14:36:40

上级 5f151a10
# 历史记录
v1.1.0 2020.7.23
+ 在 HTML 文件名称左侧填充 0,使其对齐
v1.0.0 2020.4.30
+ 正式发布
\ No newline at end of file
{
"name": "gen-epub",
"version": "1.0.1",
"version": "1.1.0",
"description": "A small tool to generate EPUB.",
"main": "src/index.js",
"scripts": {
......
......@@ -15,6 +15,11 @@ function fnameEscape(name){
return name.replace(/\\|\/|:|\*|\?|"|<|>|\|/g, '-')
}
function calcDigitCount(l) {
return (l == 0)? 1: Math.floor(Math.log10(l)) + 1
}
function writeEpub(articles, imgs, name, path) {
name = name || articles[0].title
......@@ -33,9 +38,11 @@ function writeEpub(articles, imgs, name, path) {
zip.file('META-INF/container.xml', container);
zip.file('OEBPS/Styles/Style.css', style);
var l = calcDigitCount(articles.length)
articleTemp = ejs.compile(articleTemp)
for(var [i, art] of articles.entries()) {
zip.file(`OEBPS/Text/${+i+1}.html`, articleTemp(art));
var padNum = i.toString().padStart(l, '0')
zip.file(`OEBPS/Text/${padNum}.html`, articleTemp(art));
}
for(var [fname, data] of imgs.entries()) {
......@@ -45,7 +52,7 @@ function writeEpub(articles, imgs, name, path) {
var uuid_ = uuid.v4();
var htmlToc = articles.map((art, i) => ({
title: art.title,
file: `${+i+1}.html`,
file: i.toString().padStart(l, '0') + '.html',
}))
var imgToc = Array.from(imgs.keys())
.map(fname => ({file: fname}))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册