-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcombine.sh
46 lines (46 loc) · 1.15 KB
/
combine.sh
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
if ! command -v ebook-convert &>/dev/null ;then
echo "Please install calibre to use this script"
exit 1
fi
cd novels
rm -rf "out/"
mkdir "out"
rm -rf "tmp/"
mkdir "tmp"
for novel in */; do
novel_name=$(echo $novel | sed 's/\/$//')
out="tmp/$novel_name.md"
echo Building $novel to "$out"
section=1
sectionc=0
echo "# $novel_name" >> "$out"
c=1
while [ -f "$novel/$c.md" ] ; do
chapter="$novel/$c.md"
if [ $sectionc -eq 0 ]; then
echo "" >> "$out"
echo "## 第$section卷" >> "$out"
sectionc=1
section=$[section+1]
fi
title=$(head -n 1 "${chapter}"|sed 's/^# //')
echo "" >> "$out"
echo "### $title" >> "$out"
tail -n +2 "$chapter" >> "$out"
if [ "$title" == "插图" ];then
sectionc=0
fi
c=$[c+1]
done
for pic in "$novel"/*.jpg ;do
cp "$pic" "tmp/"
done
ebook-convert "$out" "out/$novel_name.epub" \
--output-profile tablet\
--level1-toc //h:h2\
--level2-toc //h:h3\
--max-toc-links 0 \
--formatting-type markdown \
--title "$novel_name"
done
echo "done"