-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·80 lines (68 loc) · 2.08 KB
/
build.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
set -e
# Add empty line to every chapter
find chapters -name "*.md" | while read f; do tail -n1 $f | read -r _ || echo >> $f; done
MARKDOWN_OPTIONS=markdown+line_blocks+escaped_line_breaks+smart+fenced_code_blocks+fenced_code_attributes+backtick_code_blocks+yaml_metadata_block+footnotes+inline_notes+emoji
if [[ -z "${BUILD_ALL}" ]]; then
FORMATS=(pdf)
else
FORMATS=(pdf epub mobi)
fi
. ~/env/bin/activate
for format in ${FORMATS[*]}
do
echo 👉 Building $format"…"
ALL_ARGS=(
-f $MARKDOWN_OPTIONS
-F pandoc-secnos
-F pandoc-filter.py
--pdf-engine=xelatex
--standalone
--toc
--toc-depth=2
--highlight-style=kate
)
if [[ "$format" == "mobi" ]]; then
ebook-convert out/ebook_title-author_name.epub out/ebook_title-author_name.mobi --isbn 9788395736315
# kindlegen out/ebook_title-author_name.epub
else
if [[ "$format" == "pdf" ]] || [[ "$format" == "latex" ]]; then
ALL_ARGS+=(
--include-in-header=header.latex
chapters/000-metadata-pdf.yaml
)
elif [[ "$format" == "epub" ]]; then
ALL_ARGS+=(
--epub-metadata=epub-metadata.xml
--epub-cover-image=chapters/pictures/cover.jpg
--css=epub.css
--epub-embed-font=epub-fonts/Merriweather-Bold.otf
--epub-embed-font=epub-fonts/Merriweather-Regular.otf
--epub-embed-font=epub-fonts/Merriweather-Italic.otf
--epub-embed-font=epub-fonts/Merriweather-BoldItalic.otf
--epub-embed-font=epub-fonts/FiraMono-Regular.otf
--epub-embed-font=epub-fonts/FiraMono-Medium.otf
epub-imprint.md
chapters/000-metadata-epub.yaml
--number-sections
)
else
ALL_ARGS+=(
chapters/000-metadata-pdf.yaml
)
fi
ALL_ARGS+=(
chapters/000-metadata-common.yaml
chapters/*.md
)
pandoc "${ALL_ARGS[@]}" -o out/ebook_title-author_name.$format
fi
if [[ "$format" == "epub" ]]; then
cd add-headers
npm ci --legacy-peer-deps --production
node fix-epub-css.js
cd ..
fi
echo "😎 "$format" done"!
done
echo "All done! 🍾"