-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.sh
executable file
·198 lines (169 loc) · 6.7 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
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
#!/bin/bash
COURS_DIR=cours
IMG_DIR=images
LIST=cours.json
LANGUAGE=fr
FALLBACK_LANGUAGE=fr
TITLE=""
DATE=""
DOCKER_TAG=$(printenv DOCKER_TAG)
if [ -z ${DOCKER_TAG} ]; then
DOCKER_TAG="stable"
fi
build-html() {
mkdir -p output-html
ln -fs ../images output-html
echo $REVEALJSURL | grep -q http
if [ $? == 1 ]; then
cp styles/"$THEME".css $REVEALJSURL/css/theme/"$THEME".css
cp -r styles/"$THEME" $REVEALJSURL/css/theme/
fi
for cours in $((jq keys | jq -r '.[]') < $LIST); do
for module in $(jq -r '.["'"$cours"'"].modules[]' $LIST); do
if [ -f "$COURS_DIR"/"$module"."$LANGUAGE".md ]; then
cat $COURS_DIR/"$module"."$LANGUAGE".md >> "$COURS_DIR"/slide-"$cours"
elif [ -f "$COURS_DIR"/"$module"."$FALLBACK_LANGUAGE".md ]; then
echo "$module doesn't exist in $LANGUAGE. Falling back into $FALLBACK_LANGUAGE..."
cat "$COURS_DIR"/"$module"."$FALLBACK_LANGUAGE".md >> "$COURS_DIR"/slide-"$cours"
else
echo "module "$module" doesn't exist in any of the languages"
fi
done
TITLE=$(jq -r '.["'"$cours"'"].course_description' $LIST)
# Header2 are only usefull for beamer, they need to be replaced with Header3 for revealjs interpretation
sed -i 's/^## /### /' "$COURS_DIR"/slide-"$cours"
echo "Build "$TITLE" "$LANUGAGE" ("$OUTPUT")"
docker run --rm -v $PWD:/formations particule/revealjs-builder:"$DOCKER_TAG" \
--standalone \
--template=/formations/templates/template.revealjs \
--slide-level 3 \
--no-highlight \
-V theme="$THEME" \
-V navigation=frame \
-V revealjs-url="$REVEALJSURL" \
-V slideNumber=\"c/t\" \
-V title="$TITLE" \
-V institute="particule" \
-o /formations/output-html/"$cours"."$LANGUAGE".html \
/formations/"$COURS_DIR"/slide-"$cours"
rm -f "$COURS_DIR"/slide-"$cours"
# Build TP HTML
jq -r '.["'"$cours"'"].tp[]' $LIST &> /dev/null
if [ $? -eq 0 ]; then
mkdir -p output-html/tp
for tp in $(jq -r '.["'"$cours"'"].tp[]' $LIST); do
if [ -f tp/"$tp"."$LANGUAGE".md ]; then
echo "Build TP $(basename $tp)" "$LANGUAGE"
# concat TP + copyright
cat tp/$tp.$LANGUAGE.md cours/copyright.$LANGUAGE.md > $(basename $tp).md
# From markdown to html
docker run -u root --rm \
-v $PWD:/formations \
particule/grip:"$DOCKER_TAG" \
--export --title="$TITLE $(basename $tp)" /formations/$(basename $tp).md /formations/output-html/tp/$(basename $tp)."$LANGUAGE".html
elif [ -f tp/"$tp"."$FALLBACK_LANGUAGE".md ]; then
echo "$tp doesn't exist in $LANGUAGE. Falling back into $FALLBACK_LANGUAGE..."
# concat TP + copyright
cat tp/$tp.$FALLBACK_LANGUAGE.md cours/copyright.$FALLBACK_LANGUAGE.md > $tp.md
# From markdown to html
docker run --rm \
-v $PWD:/formations \
particule/grip:"$DOCKER_TAG" \
--export --title="$TITLE $(basename $tp)" /formations/$tp.md /formations/output-html/tp/$(basename $tp).$FALLBACK_LANGUAGE.html
else
echo "TP $(basename $tp) doesn't exist in any of the languages"
fi
rm $(basename $tp).md
done
fi
done
}
build-pdf() {
mkdir -p output-pdf
for cours in $((jq keys | jq -r '.[]') < $LIST); do
echo "Build "$cours" "$LANUGAGE" ("$OUTPUT")"
docker run --rm \
-v $PWD/output-pdf:/output \
-v $PWD/output-html/"$cours"."$LANGUAGE".html:/index.html \
-v $PWD/images:/images particule/wkhtmltopdf:$DOCKER_TAG \
-O landscape \
-s A5 \
-T 0 -B 0 file:///index.html\?print-pdf /output/"$cours"."$LANGUAGE".pdf
# Build TP
jq -r '.["'"$cours"'"].tp[]' $LIST &> /dev/null
if [ $? -eq 0 ]; then
mkdir -p output-pdf/tp
for tp in $(jq -r '.["'"$cours"'"].tp[]' $LIST); do
if [ -f tp/"$tp"."$LANGUAGE".md ]; then
echo "Build TP $(basename $tp)" "$LANGUAGE"
docker run --rm -u root -v $PWD:/formations particule/markdown-pdf:"$DOCKER_TAG" \
-o /formations/output-pdf/tp/$(basename $tp)."$LANGUAGE".pdf /formations/tp/$tp.$LANGUAGE.md /formations/cours/copyright.$LANGUAGE.md
elif [ -f tp/"$tp"."$FALLBACK_LANGUAGE".md ]; then
echo "$tp doesn't exist in $LANGUAGE. Falling back into $FALLBACK_LANGUAGE..."
echo "Build TP $(basename $tp)" "$FALLBACK_LANGUAGE"
docker run --rm -u root -v $PWD:/formations particule/markdown-pdf:"$DOCKER_TAG" \
-o /formations/output-pdf/tp/$(basename $tp)."$FALLBACK_LANGUAGE".pdf /formations/tp/$tp.$FALLBACK_LANGUAGE.md /formations/cours/copyright.$FALLBACK_LANGUAGE.md
else
echo "TP $(basename $tp) doesn't exist in any of the languages"
fi
done
fi
done
}
display_help() {
cat <<EOF
USAGE : $0 options
-o output Output format (html, pdf or all). Default: all
-t theme Theme to use. Default: particule
-u revealjsURL RevealJS URL that need to be use. If you are building
training courses on a local environment you should git
clone https://github.com/hakimel/reveal.js and set
this variable to your local copy.
This option is also necessary even if you only want PDF
output. Default: https://particule.io/formations/revealjs
-c course Which course to build: "all" to build them all !
-l language Language in which you want the course to be built. Default: fr
EOF
exit 0
}
while getopts ":o:t:u:c:l:h" OPT; do
case $OPT in
h) display_help ;;
c) COURSE="$OPTARG";;
o) OUTPUT="$OPTARG";;
t) THEME="$OPTARG";;
u) REVEALJSURL="$OPTARG";;
l) LANGUAGE="$OPTARG";;
?)
echo "Invalid option: -$OPTARG" >&2
display_help
exit 1
;;
esac
done
[[ $REVEALJSURL == "" ]] && REVEALJSURL="https://particule.io/formations/revealjs"
if [[ $THEME == "" ]]; then
THEME="particule"
else
ls styles/"$THEME".css &> /dev/null
[ $? -eq 2 ] && echo "Theme $THEME doesn't exist" && exit 1
fi
if [[ $COURSE != "" ]]; then
(echo "{ \"$COURSE\":" && jq -r '.["'"$COURSE"'"]' $LIST && echo "}") | jq '.' > cours.json.tmp
[ $? -eq 1 ] && echo "Course $COURSE doesn't exist, please refer to cours.list" && exit 1
LIST=cours.json.tmp
else
LIST=cours.json
fi
OUTPUT=${OUTPUT:-all}
if [[ ! $OUTPUT =~ html|pdf|all ]]; then
echo "Invalid option: either html, pdf or all" >&2
display_help
exit 1
elif [[ $OUTPUT == "html" ]]; then
build-html
elif [[ $OUTPUT == "pdf" || $OUTPUT == "all" ]]; then
build-html
build-pdf
fi
rm -f cours.json.tmp