This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
/
build.sh
executable file
·162 lines (149 loc) · 4.09 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
#
# build.sh - Build the book in target/.
#
# Options:
#
# -f <formats>
# comma-separated list of formats to build.
# Valid formats: pdf, chunked, html, epub
# Defaults to "pdf,chunked"
#
# -v enable verbose output
#
# Environment variables used:
#
# ASCIIDOC asciidoc command to use. Defaults to "asciidoc".
# Fail if anything errors
set -e
# Fail if a function call is missing an argument
set -u
# Parse arguments
formats_arg="pdf,chunked"
verbose=0
while getopts "vf:" opt; do
case "$opt" in
v) verbose=1
;;
f) formats_arg=$OPTARG
;;
esac
done
IFS="," read -a formats <<< "$formats_arg"
if [ "$verbose" = 1 ]; then
vflag="-v"
dblatex_vflag="-V"
zip_vflag="-v"
else
vflag=""
dblatex_vflag="-q"
zip_vflag="-q"
fi
if [ -z "${ASCIIDOC+x}" ]; then ASCIIDOC=asciidoc; fi
asciidoc_exe="$ASCIIDOC"
function array_contains() {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
valid_formats=( pdf chunked html epub )
for format in ${formats[@]}; do
if ! array_contains "$format" "${valid_formats[@]}"; then
echo "Error: invalid format: '$format'" >&2
exit 1
fi
done
book=book-mvnex
book_file=$book.asciidoc
mkdir target
# Build the Single Page HTML
if array_contains "html" "${formats[@]}"; then
echo "Building Single Page HTML"
$asciidoc_exe $vflag -o target/$book.html $book_file
fi
dblatex_opts_common="$dblatex_vflag -P doc.publisher.show=0 -P latex.output.revhistory=0"
# Build the PDF
if array_contains "pdf" "${formats[@]}"; then
echo "Building PDF"
cp -r figs target
cp -r images target
$asciidoc_exe $vflag -d book -b docbook \
-o target/$book.xml $book_file
xmllint --nonet --noout --valid target/$book.xml
dblatex -t pdf $dblatex_opts_common \
-p docbook-xsl/dblatex.xsl \
-s latex/asciidoc-dblatex.sty \
-s latex/custom-docbook.sty \
target/$book.xml
echo "done"
fi
run_xslt_fcn() {
fcn=$1
if [ "$verbose" = 1 ]; then
$fcn
else
# Sadly, xsltproc lists all files written on STDERR
$fcn 2>/dev/null
fi
}
# Build the Chunked HTML
if array_contains "chunked" "${formats[@]}"; then
echo "Building Multi Page HTML"
$asciidoc_exe $vflag -d book -b docbook \
-o target/$book.xml $book_file
xmllint --nonet --noout --valid target/$book.xml
(
cd target
chunked_dir=$book.chunked
xslt_chunked() {
# Don't include $vflag in xsltproc. It's just *too* verbose.
xsltproc --stringparam chunk.section.depth 1 \
--stringparam callout.graphics 0 --stringparam navig.graphics 0 \
--stringparam admon.textlabel 1 --stringparam admon.graphics 0 \
--stringparam toc.section.depth 1 --stringparam base.dir "$chunked_dir" \
../docbook-xsl/custom-chunked.xsl \
"$book.xml"
}
run_xslt_fcn xslt_chunked
mkdir -p $chunked_dir/figs
cp ../docbook-xsl/docbook-xsl.css $chunked_dir
cp -r ../figs/web $chunked_dir/figs
)
[ $? = 0 ] || exit 1
echo "done"
fi
# Build the EPUB
if array_contains "epub" "${formats[@]}"; then
echo "Building EPUB"
$asciidoc_exe $vflag -d book -b docbook \
-o target/$book.xml $book_file
xmllint --nonet --noout --valid target/$book.xml
(
cd target
epub_dir=$book.epub.d
mkdir -p $epub_dir
cd $epub_dir
xslt_epub() {
# Don't include $vflag in xsltproc. It's just *too* verbose.
xsltproc --stringparam chunk.section.depth 0\
--stringparam callout.graphics 0 --stringparam navig.graphics 0 \
--stringparam admon.textlabel 1 --stringparam admon.graphics 0 \
--stringparam toc.section.depth 1 \
../../docbook-xsl/epub.xsl \
"../$book.xml"
}
run_xslt_fcn xslt_epub
oebps=OEBPS
cp -r ../../covers $oebps
mkdir -p $oebps/figs
cp -r ../../figs/web $oebps/figs
cp ../../docbook-xsl/docbook-xsl.css $oebps
mkdir -p $oebps/images/icons
cp -r ../../images/icons/callouts $oebps/images/icons
echo 'application/epub+zip' > mimetype
zip $zip_vflag -Z store ../book-mvnex.epub mimetype
zip $zip_vflag -r -u ../book-mvnex.epub *
)
[ $? = 0 ] || exit 1
echo "done"
fi