Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
gen-epub
提交
eaf27af2
G
gen-epub
项目概览
OpenDocCN
/
gen-epub
通知
1
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gen-epub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
eaf27af2
编写于
2月 26, 2020
作者:
W
wizardforcel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
2020-02-26 15:12:50
上级
5833af45
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
12 deletion
+19
-12
index.js
index.js
+18
-11
package.json
package.json
+1
-1
未找到文件。
index.js
浏览文件 @
eaf27af2
...
...
@@ -21,13 +21,19 @@ function writeEpub(articles, imgs, name, path) {
path
=
path
||
fnameEscape
(
name
)
+
'
.epub
'
if
(
!
path
.
endsWith
(
'
.epub
'
))
path
+=
'
.epub
'
var
zip
=
new
jszip
();
zip
.
file
(
'
mimetype
'
,
fs
.
readFileSync
(
d
(
'
./assets/mimetype
'
)));
zip
.
file
(
'
META-INF/container.xml
'
,
fs
.
readFileSync
(
d
(
'
./assets/container.xml
'
)));
zip
.
file
(
'
OEBPS/Styles/Style.css
'
,
fs
.
readFileSync
(
d
(
'
./assets/Style.css
'
)));
var
mimetype
=
fs
.
readFileSync
(
d
(
'
./assets/mimetype
'
))
var
container
=
fs
.
readFileSync
(
d
(
'
./assets/container.xml
'
))
var
style
=
fs
.
readFileSync
(
d
(
'
./assets/Style.css
'
))
var
articleTemp
=
fs
.
readFileSync
(
d
(
'
assets/article.ejs
'
),
'
utf-8
'
)
var
contentTemp
=
fs
.
readFileSync
(
d
(
'
assets/content.ejs
'
),
'
utf-8
'
)
var
tocTemp
=
fs
.
readFileSync
(
d
(
'
assets/toc.ejs
'
),
'
utf-8
'
)
var
articleTemp
=
ejs
.
compile
(
fs
.
readFileSync
(
d
(
'
assets/article.ejs
'
),
'
utf-8
'
))
var
zip
=
new
jszip
();
zip
.
file
(
'
mimetype
'
,
mimetype
);
zip
.
file
(
'
META-INF/container.xml
'
,
container
);
zip
.
file
(
'
OEBPS/Styles/Style.css
'
,
style
);
articleTemp
=
ejs
.
compile
(
articleTemp
)
for
(
var
[
i
,
art
]
of
articles
.
entries
())
{
zip
.
file
(
`OEBPS/Text/
${
+
i
+
1
}
.html`
,
articleTemp
(
art
));
}
...
...
@@ -37,7 +43,6 @@ function writeEpub(articles, imgs, name, path) {
}
var
uuid
=
uuidGenerator
.
uuid
();
var
htmlToc
=
articles
.
map
((
art
,
i
)
=>
({
title
:
art
.
title
,
file
:
`
${
+
i
+
1
}
.html`
,
...
...
@@ -45,22 +50,24 @@ function writeEpub(articles, imgs, name, path) {
var
imgToc
=
Array
.
from
(
imgs
.
keys
())
.
map
(
fname
=>
({
file
:
fname
}))
var
opf
=
ejs
.
render
(
fs
.
readFileSync
(
d
(
'
assets/content.ejs
'
),
'
utf-8
'
)
,
{
var
co
=
ejs
.
render
(
contentTemp
,
{
date
:
moment
().
format
(
'
YYYY-MM-DD
'
),
imgToc
:
imgToc
,
htmlToc
:
htmlToc
,
uuid
:
uuid
,
name
:
name
,
});
zip
.
file
(
'
OEBPS/content.opf
'
,
opf
);
zip
.
file
(
'
OEBPS/content.opf
'
,
co
);
var
ncx
=
ejs
.
render
(
fs
.
readFileSync
(
d
(
'
assets/toc.ejs
'
),
'
utf-8
'
)
,
{
var
toc
=
ejs
.
render
(
tocTemp
,
{
toc
:
htmlToc
,
uuid
:
uuid
,
});
zip
.
file
(
'
OEBPS/toc.ncx
'
,
ncx
);
zip
.
file
(
'
OEBPS/toc.ncx
'
,
toc
);
var
data
=
zip
.
generate
({
base64
:
false
,
'
compression
'
:
'
DEFLATE
'
})
if
(
!
zip
.
generate
)
throw
ReferenceError
(
'
please install the sync version of jszip
'
)
var
data
=
zip
.
generate
({
base64
:
false
,
compression
:
'
DEFLATE
'
})
fs
.
writeFileSync
(
path
,
data
,
'
binary
'
)
}
...
...
package.json
浏览文件 @
eaf27af2
{
"name"
:
"gen-epub"
,
"version"
:
"0.1.
0
"
,
"version"
:
"0.1.
5
"
,
"description"
:
""
,
"main"
:
"index.js"
,
"scripts"
:
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录