-
Notifications
You must be signed in to change notification settings - Fork 16
/
build_html.sh
executable file
·89 lines (72 loc) · 2.46 KB
/
build_html.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
#!/usr/bin/env bash
# build_html.sh
# build website based on jupyter notebooks
# ask tablesaw to plot <img> for Sphinx to load
# export D2L_PLOT_IMAGE=1
set -e
rm -r -f */temp.ipynb
output_dir=_build/eval
mkdir -p $output_dir
aws s3 sync s3://d2l-java-resources/d2l-original .
mkdir -p $output_dir/img
cp -r img/* $output_dir/img
cp d2l.bib $output_dir
python3 tools/add_online_runner.py
set +e
echo "Try to fetch backup"
COMMIT_ID=$(git rev-parse --short HEAD)
D2L_LANG="${D2L_LANG:-en}"
if [[ "$BUILD_TYPE" == "release" ]]; then
unset MAX_EPOCH
unset DATASET_LIMIT
DATE=$(date '+%Y-%m-%d')
S3_PREFIX="$D2L_LANG/$DATE"
else
S3_PREFIX="$D2L_LANG/$COMMIT_ID"
fi
aws s3 sync "s3://d2l-java-notebook/${S3_PREFIX}" .
set -e
d2lbook build eval
function eval {
base=$(basename $1)
dir=$(dirname $1)
if [ -f "$output_dir/$1" ]; then
echo "$output_dir/$1 exists, skipping."
return 0
fi
echo "Evaluating file: $1"
echo "saving output to: $output_dir/$1"
jupyter nbconvert --to notebook --execute --ExecutePreprocessor.timeout=7200 --output temp "$1"
mkdir -p $output_dir/$dir
mv "$dir/temp.ipynb" "$output_dir/$1"
aws s3 cp "$output_dir/$1" "s3://d2l-java-notebook/${S3_PREFIX}/$output_dir/$1"
}
for f in **/*.ipynb
do
eval "$f"
done
rm -r -f */temp.ipynb
# download additional js to be included
curl -O https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js
d2lbook build rst
cp "static/frontpage/frontpage_$D2L_LANG.html" _build/rst/frontpage.html
mkdir -p _build/rst/chapter_references/
mv zreferences.rst _build/rst/chapter_references/
d2lbook build html
mkdir -p _build/html/_images/
cp -r static/frontpage/_images/* _build/html/_images/
wget https://raw.githubusercontent.com/mli/mx-theme/master/mxtheme/static/sphinx_materialdesign_theme.css.map
wget https://raw.githubusercontent.com/mli/mx-theme/master/mxtheme/static/sphinx_materialdesign_theme.js.map
mv sphinx_materialdesign_theme.css.map _build/html/
mv sphinx_materialdesign_theme.js.map _build/html/
sed -e 's/<blockquote>//g' -i _build/html/index.html
sed -e 's/<\/blockquote>//g' -i _build/html/index.html
for fn in `find _build/html/_images/ -iname '*.svg' `; do
if [[ $fn == *'qr_'* ]] ; then # || [[ $fn == *'output_'* ]]
continue
fi
# rsvg-convert installed on ubuntu changes unit from px to pt, so evening no
# change of the size makes the svg larger...
rsvg-convert -z 1 -f svg -o tmp.svg $fn
mv tmp.svg $fn
done