-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpandoc-build.sh
executable file
·219 lines (184 loc) · 5.46 KB
/
pandoc-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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
# e.g
# pandoc-build.sh source.md paper
#
# All being well, the above command will output
# ../build/paper/source.pdf
# or
# pandoc-build.sh source.md presentation
#
# All being well, the above command will output
# ../build/presentation/index.html
# and put reveal.js in ./build/presentation/
function install_precheck {
for FILE in `echo "${src_md}"`
do
#echo $FILE
#target_name="`basename ${FILE} | sed 's/\(.*\)\..*/\1/'`"
src_dir="`dirname ${FILE}`"
if [ ! -f "${FILE}" ]
then
echo "error: the source markdown (${FILE}) does not exist!"
exit 1
fi
#If the markdown has image references, check for the actual images
if [ -n "`grep '(images/' ${FILE}`" ]
then
if [ ! -d "${src_dir}/${src_images}" ]
then
echo "error: the image directory ${src_dir}/${src_images} does not exist!"
exit 1
elif [ -z "`ls ${src_dir}/${src_images}`" ]
then
echo "error: there are no images!"
exit 1
fi
fi
#If the markdown has video references, check for the actual images
if [ -n "`grep '(videos/' ${FILE}`" ]
then
if [ ! -d "${src_dir}/${src_videos}" ]
then
echo "error: the video directory ${src_dir}/${src_videos} does not exist!"
exit 1
elif [ -z "`ls ${src_dir}/${src_videos}`" ]
then
echo "error: there are no videos!"
exit 1
fi
fi
done
# Change directory to the markdown source directory so the image references in the source resolve correctly
cd ${src_dir}
}
function install_paper {
#echo "Source dir is ${src_dir}"
src_meta="meta.yml"
src_biblio="bibliography/library.bib"
src_csl="bibliography/apa.csl"
target_dir="${this_dir}/build/paper/${target_name}"
target_paper="${target_dir}/${target_name}.docx"
if [ ! -f "${src_biblio}" ]
then
echo "error: the source bibliography ${src_dir}/${src_biblio} does not exist!"
exit 1
fi
if [ ! -f "${src_csl}" ]
then
echo "error: the source csl ${src_dir}/${src_csl} does not exist!"
exit 1
fi
if [ ! -f "${src_meta}" ]
then
echo "error: the source meta ${src_dir}/${src_meta} does not exist!"
exit 1
fi
if [ ! -d "${target_dir}" ]
then
mkdir -p "${target_dir}"
fi
#pandoc --normalize --toc --metadata link-citations=true --filter pandoc-citeproc -V documentclass=report "${src_meta}" "${src_md}" --biblio "${src_biblio}" --csl "${src_csl}" --pdf-engine=xelatex -s -S -o "${target_paper}"
#echo "pandoc --metadata link-citations=true --filter pandoc-citeproc -V documentclass=report ${src_meta} --biblio ${src_biblio} --csl ${src_csl} --latex-engine=xelatex -s -o ${target_paper}"
#pandoc --metadata-file=${src_meta} link-citations=true --filter pandoc-citeproc -V documentclass=report ${src_meta} ${src_md} --biblio ${src_biblio} --csl ${src_csl} --pdf-engine=xelatex -s -o ${target_paper}
pandoc --metadata link-citations=true --filter pandoc-citeproc -V documentclass=report ${src_meta} ${src_md} --biblio ${src_biblio} --csl ${src_csl} --pdf-engine=xelatex -s -o ${target_paper}
}
function install_presentation {
src_meta="meta.yml"
src_css="${target_name}.css"
src_reveal="${this_dir}/library/reveal.js"
target_dir="${this_dir}/build/presentation/${target_name}"
target_html="${target_dir}/index.html"
target_reveal="${target_dir}/reveal.js"
# Possible reveal themes
# Black (default) - White - League - Sky - Beige - Simple
# Serif - Blood - Night - Moon - Solarized
# Liked themes
# Black, White, Night, Solarized
theme="white"
transition="linear"
if [ ! -f "${src_meta}" ]
then
echo "error: the source meta ${src_meta} does not exist!"
exit 1
fi
if [ ! -f "${src_css}" ]
then
echo "error: the source css ${src_css} does not exist!"
exit 1
fi
if [ ! -d "${src_reveal}" ]
then
echo "error: ${src_reveal} does not exist. Please download reveal (https://github.com/hakimel/reveal.js/) and copy it into ${src_reveal}"
exit 1
fi
if [ ! -d "${target_dir}" ]
then
mkdir -p "${target_dir}"
fi
#pandoc -s -S --section-divs --variable theme="$theme" --variable transition="$transition" -t revealjs -H "${src_css}" "${src_md}" -o "${target_html}"
#pandoc --metadata-file=${src_meta} --section-divs --variable theme=$theme --variable transition=$transition -t revealjs -H ${src_css} ${src_md} -o ${target_html}
pandoc --section-divs --variable theme=$theme --variable transition=$transition -t revealjs -H ${src_css} ${src_md} -o ${target_html}
# Now place images, videos and reveal
if [ -d "${src_images}" ]
then
cp -fRp "${src_images}" "${target_dir}"
fi
if [ -d "${src_videos}" ]
then
cp -fRp "${src_videos}" "${target_dir}"
fi
if [ ! -d "${target_reveal}" ]
then
cp -fRp "${src_reveal}" "${target_reveal}"
cd "${target_reveal}" && npm install && cd -
fi
}
if [ -z "`which pandoc`" ]
then
echo "error: you must install pandoc!"
exit 1
fi
#if [ -z "`which xelatex`" ]
#then
# echo "error: you must install LaTeX (or BasicTeX)!"
# exit 1
#fi
target_name=$1
action=$2
shift 2
src_md=$@
#echo $target_name
#echo $action
#echo $src_md
if [ -z "$target_name" ]
then
echo "usage: $0 outputName {presentation||paper} input"
exit 1
fi
if [ -z "$action" ]
then
echo "usage: $0 outputName {presentation||paper} input"
exit 1
fi
if [ -z "$src_md" ]
then
echo "usage: $0 outputName {presentation||paper} input"
exit 1
fi
this_dir="`dirname $(pwd)`"
src_dir=""
src_images="images"
src_videos="videos"
case "$action" in
presentation)
install_precheck
install_presentation
;;
paper)
install_precheck
install_paper
;;
*)
echo "usage: $0 outputName {presentation||paper} input"
exit 1
esac