Skip to content

Commit b687c1e

Browse files
committed
feature: 增加生成 epub 格式的文件
1 parent 988f3aa commit b687c1e

File tree

5 files changed

+284
-1
lines changed

5 files changed

+284
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.code/
33
__pycache__/
44
.DS_Store
5-
tmp/
5+
tmp/
6+
output/

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ doc:
99
translate:
1010
bin/zh-tw.py
1111

12+
epub:
13+
bin/epub
14+
1215
.PHONY: default doc translate

bin/epub

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
# Set the directory containing Markdown files
6+
SCRIPT_DIR=$(dirname "$0")
7+
INPUT_DIR=$(cd "$(dirname "$SCRIPT_DIR")" && pwd)
8+
OUTPUT_DIR="$INPUT_DIR/output"
9+
10+
# Create output directory if it doesn't exist
11+
mkdir -p "$OUTPUT_DIR"
12+
13+
convert_to_epub() {
14+
# convert all EPUB files into a single EPUB book
15+
OUTPUT_BOOK="$OUTPUT_DIR/ddia.epub"
16+
rm -f "$OUTPUT_BOOK"
17+
echo "Converting all EPUB files into $OUTPUT_BOOK..."
18+
19+
local meta_file=${INPUT_DIR}/metadata.yaml
20+
local css_file=${INPUT_DIR}/js/epub.css
21+
22+
pandoc -o "$OUTPUT_BOOK" "$meta_file" \
23+
--toc-depth=2 \
24+
--top-level-division=chapter \
25+
--file-scope=true \
26+
--css="$css_file" \
27+
--webtex \
28+
--wrap=preserve \
29+
"${INPUT_DIR}"/SUMMARY.md \
30+
"${INPUT_DIR}"/README.md \
31+
"${INPUT_DIR}"/preface.md \
32+
"${INPUT_DIR}"/part-i.md \
33+
"${INPUT_DIR}"/ch1.md \
34+
"${INPUT_DIR}"/ch2.md \
35+
"${INPUT_DIR}"/ch3.md \
36+
"${INPUT_DIR}"/ch4.md \
37+
"${INPUT_DIR}"/part-ii.md \
38+
"${INPUT_DIR}"/ch5.md \
39+
"${INPUT_DIR}"/ch6.md \
40+
"${INPUT_DIR}"/ch7.md \
41+
"${INPUT_DIR}"/ch8.md \
42+
"${INPUT_DIR}"/ch9.md \
43+
"${INPUT_DIR}"/part-iii.md \
44+
"${INPUT_DIR}"/ch10.md \
45+
"${INPUT_DIR}"/ch11.md \
46+
"${INPUT_DIR}"/ch12.md \
47+
"${INPUT_DIR}"/colophon.md \
48+
"${INPUT_DIR}"/glossary.md
49+
50+
echo "Converted EPUB book created at $OUTPUT_BOOK."
51+
}
52+
53+
convert_to_epub

js/epub.css

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
/* This defines styles and classes used in the book */
2+
@page {
3+
margin: 10px;
4+
}
5+
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p,
6+
blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img,
7+
ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center,
8+
fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td,
9+
article, aside, canvas, details, embed, figure, figcaption, footer, header,
10+
hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video, ol,
11+
ul, li, dl, dt, dd {
12+
margin: 0;
13+
padding: 0;
14+
border: 0;
15+
font-size: 100%;
16+
vertical-align: baseline;
17+
}
18+
html {
19+
line-height: 1.2;
20+
font-family: Georgia, serif;
21+
color: #1a1a1a;
22+
}
23+
p {
24+
text-indent: 0;
25+
margin: 1em 0;
26+
widows: 2;
27+
orphans: 2;
28+
}
29+
a, a:visited {
30+
color: #1a1a1a;
31+
}
32+
img {
33+
max-width: 100%;
34+
}
35+
sup {
36+
vertical-align: super;
37+
font-size: smaller;
38+
}
39+
sub {
40+
vertical-align: sub;
41+
font-size: smaller;
42+
}
43+
h1 {
44+
margin: 3em 0 0 0;
45+
font-size: 2em;
46+
page-break-before: always;
47+
line-height: 150%;
48+
}
49+
h2 {
50+
margin: 1.5em 0 0 0;
51+
font-size: 1.5em;
52+
line-height: 135%;
53+
}
54+
h3 {
55+
margin: 1.3em 0 0 0;
56+
font-size: 1.3em;
57+
}
58+
h4 {
59+
margin: 1.2em 0 0 0;
60+
font-size: 1.2em;
61+
}
62+
h5 {
63+
margin: 1.1em 0 0 0;
64+
font-size: 1.1em;
65+
}
66+
h6 {
67+
font-size: 1em;
68+
}
69+
h1, h2, h3, h4, h5, h6 {
70+
text-indent: 0;
71+
text-align: left;
72+
font-weight: bold;
73+
page-break-after: avoid;
74+
page-break-inside: avoid;
75+
}
76+
77+
ol, ul {
78+
margin: 1em 0 0 1.7em;
79+
}
80+
li > ol, li > ul {
81+
margin-top: 0;
82+
}
83+
blockquote {
84+
margin: 1em 0 1em 1.7em;
85+
}
86+
code {
87+
font-family: Menlo, Monaco, 'Lucida Console', Consolas, monospace;
88+
font-size: 85%;
89+
margin: 0;
90+
hyphens: manual;
91+
}
92+
/*pre {*/
93+
/* margin: 1em 0;*/
94+
/* overflow: auto;*/
95+
/*}*/
96+
pre code {
97+
white-space: pre-wrap;
98+
word-wrap: break-word;
99+
background-color: #f5f5f5;
100+
padding: 1em;
101+
}
102+
.sourceCode {
103+
background-color: transparent;
104+
overflow: visible;
105+
}
106+
hr {
107+
background-color: #1a1a1a;
108+
border: none;
109+
height: 1px;
110+
margin: 1em 0;
111+
}
112+
table {
113+
margin: 1em 0;
114+
border-collapse: collapse;
115+
width: 100%;
116+
overflow-x: auto;
117+
display: block;
118+
}
119+
table caption {
120+
margin-bottom: 0.75em;
121+
}
122+
tbody {
123+
margin-top: 0.5em;
124+
border-top: 1px solid #1a1a1a;
125+
border-bottom: 1px solid #1a1a1a;
126+
}
127+
th, td {
128+
padding: 0.25em 0.5em 0.25em 0.5em;
129+
}
130+
th {
131+
border-top: 1px solid #1a1a1a;
132+
}
133+
header {
134+
margin-bottom: 4em;
135+
text-align: center;
136+
}
137+
#TOC li {
138+
list-style: none;
139+
}
140+
#TOC ul {
141+
padding-left: 1.3em;
142+
}
143+
#TOC > ul {
144+
padding-left: 0;
145+
}
146+
#TOC a:not(:hover) {
147+
text-decoration: none;
148+
}
149+
code {
150+
white-space: pre-wrap;
151+
}
152+
span.smallcaps {
153+
font-variant: small-caps;
154+
}
155+
156+
/* This is the most compatible CSS, but it only allows two columns: */
157+
div.column {
158+
display: inline-block;
159+
vertical-align: top;
160+
width: 50%;
161+
}
162+
/* If you can rely on CSS3 support, use this instead: */
163+
/* div.columns {
164+
display: flex;
165+
gap: min(4vw, 1.5em);
166+
}
167+
div.column {
168+
flex: auto;
169+
overflow-x: auto;
170+
} */
171+
172+
div.hanging-indent {
173+
margin-left: 1.5em;
174+
text-indent: -1.5em;
175+
}
176+
ul.task-list {
177+
list-style: none;
178+
}
179+
ul.task-list li input[type="checkbox"] {
180+
width: 0.8em;
181+
margin: 0 0.8em 0.2em -1.6em;
182+
vertical-align: middle;
183+
}
184+
.display.math {
185+
display: block;
186+
text-align: center;
187+
margin: 0.5rem auto;
188+
}
189+
190+
/* For title, author, and date on the cover page */
191+
h1.title { }
192+
p.author { }
193+
p.date { }
194+
195+
nav#toc ol, nav#landmarks ol {
196+
padding: 0;
197+
margin-left: 1em;
198+
}
199+
nav#toc ol li, nav#landmarks ol li {
200+
list-style-type: none;
201+
margin: 0;
202+
padding: 0;
203+
}
204+
a.footnote-ref {
205+
vertical-align: super;
206+
}
207+
em, em em em, em em em em em {
208+
font-style: italic;
209+
}
210+
em em, em em em em {
211+
font-style: normal;
212+
}
213+
q {
214+
quotes: "“" "”" "‘" "’";
215+
}
216+
@media screen { /* Workaround for iBooks issue; see #6242 */
217+
.sourceCode {
218+
overflow: visible !important;
219+
white-space: pre-wrap !important;
220+
}
221+
}

metadata.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: 设计数据密集型应用
3+
author: Martin Kleppmann
4+
rights: Creative Commons Non-Commercial Share Alike 3.0
5+
language: 中文

0 commit comments

Comments
 (0)