-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild-slide
executable file
·191 lines (167 loc) · 5.46 KB
/
build-slide
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
#!/bin/bash
export SEMESTER=fall
export YEAR=2024
bootstraproot=https://bootstrapworld.org/materials/$SEMESTER$YEAR
SED=sed
if which gsed|grep -q .; then
SED=gsed
fi
regenid=
rebuild=
export OLDFORMAT
export PROGLANG
export PD
nomake=
lsn=
if test $# -eq 0; then
echo build-slide needs a lesson argument
exit
else
while test $# -ne 0; do
if test "$1" = -f; then
regenid=1; shift
elif test "$1" = -old; then
OLDFORMAT=1; shift
elif test "$1" = -z; then
echo WARNING: Obsolete option $1; regenid=1; shift
elif test "$1" = --proglang; then
shift; PROGLANG="$1"; shift
elif test "$1" = --nomake; then
nomake=1; shift
elif test "$1" = --pd; then
PD=1; shift
elif test "$1" = --rebuild; then
rebuild=y; shift
else
lsn="$1"; shift
fi
done
fi
lsn=${lsn%/}
lsn=${lsn##*/}
if test "$PROGLANG" = wescheme; then
lsn=$(echo $lsn|$SED -e 's/-wescheme$//')
lsn=$lsn-wescheme
elif test "$PROGLANG" = codap; then
lsn=$(echo $lsn|$SED -e 's/-codap$//')
lsn=$lsn-codap
fi
if echo $lsn|grep -q "\-wescheme$"; then
PROGLANG=wescheme
elif echo $lsn|grep -q "\-codap$"; then
PROGLANG=codap
fi
if test -z "$PROGLANG"; then
PROGLANG=pyret
fi
export TOPDIR=$(pwd)
templateSlidesId=1vFGtTzhTlc1p8VJECRucj5DO83skm4wMI1BU3QbHE5k
parentFolderId=1AP4vk0XwLSl9cU8HIHjmSTFK7dG3CrGn
# md2googleslides can optionally take a path to a CSS file,
# which is used for highlighting code. We use our standard
# CSS file for this
cssPath=$TOPDIR/distribution/en-us/lib/shared.css
if test -z "$nomake"; then
make
fi
if test ! -d distribution; then
echo WARNING: Did not find any built pathways
exit
else
cd distribution
if test -s .make.error.log; then
echo make failed\; build-slide aborted
exit
fi
fi
export NATLANG
for NATLANG in *; do
test -d $NATLANG || continue
export PROGDIR=$TOPDIR/distribution/.prog-$NATLANG
if test ! -d $NATLANG/lessons; then
echo Missing lessons directory in distribution/$NATLANG -- did you call make\?
continue
fi
if test ! -d $NATLANG/lessons/$lsn; then
echo Lesson $NATLANG/lessons/$lsn not found in distribution
continue
fi
cd $NATLANG/lessons/$lsn
export BOOTSTRAPPREFIX="$bootstraproot/$NATLANG"
export LESSON="$lsn"
# echo Doing $LESSON
repoLESSON=$(cat .repodir.txt.kp)
# echo repoLESSON is $repoLESSON
slidesmd=zlides.md
if test -z "$PD"; then
slidesprefix='slides'
else
slidesprefix='slides-pd'
fi
slidesmkd=$slidesprefix.mkd
idfile=$slidesprefix-$PROGLANG.id
if test -n "$OLDFORMAT"; then
slidesmd=slides.md
fi
if test -n "$regenid"; then
rm -f $idfile
fi
if test -f $slidesmd; then
$TOPDIR/lib/slides-preproc.rkt $slidesmd $slidesmkd
if test -f $slidesmkd; then
title=$(grep '^# ' $slidesmkd|$SED -e 1q|$SED -e 's/^# *//')
title="AUTO-GEN:$title - $PROGLANG"
# warn if used without -f and --rebuild
if test -z "$regenid"; then
if test -f "$idfile"; then
if test -z "$rebuild"; then
read -p "This will REPLACE A PUBLIC FILE! Are you *sure* you want to rebuild slides for $lsn? (If not, use build-slide -f to make a new file id.) [yn] " goahead
test "$goahead" != y && break
fi
fi
fi
if test -s "$idfile"; then
id=$(cat "$idfile"|$SED -e 1q)
# echo md2gslides with id $id
node $TOPDIR/node_modules/md2googleslides/bin/md2gslides.js $slidesmkd -a "$id" -e -n -t "$title" -c $templateSlidesId -p $parentFolderId -s $cssPath --use-fileio > .tmp.txt
# node $TOPDIR/node_modules/md2googleslides/bin/md2gslides.js $slidesmkd -a "$id" -e -n -t "$title" --use-fileio > .tmp.txt 2>.tmpe.txt
if grep -q 'Unable to generate slides' .tmp.txt; then
echo Slides failed for $LESSON/$slidesmkd
if grep -q 'must be less than the endIndex' .tmp.txt; then
echo You likely have a slide with text preceding table
fi
cat .tmp.txt
fi
# rm .tmp.txt
else
# echo md2gslides without id
$TOPDIR/node_modules/md2googleslides/bin/md2gslides.js $slidesmkd -n -t "$title" -c $templateSlidesId -p $parentFolderId -s $cssPath --use-fileio > .tmp.txt
if grep -q 'Unable to generate slides' .tmp.txt; then
echo Slides failed for $LESSON/$slidesmkd
if grep -q 'must be less than the endIndex' .tmp.txt; then
echo You likely have a slide with text preceding table
fi
cat .tmp.txt
else
grep 'View your presentation at' .tmp.txt | $SED -e 's/.*docs\.google\.com\/presentation\/d\///' > "$idfile"
cp "$idfile" $TOPDIR/$repoLESSON/
echo Remember to push $repoLESSON/$idfile to Git repo
fi
fi
if test -f "$idfile"; then
id=$(cat "$idfile"|$SED -e 1q)
slideurl="https:\/\/docs.google.com\/presentation\/d\/$id"
echo '<meta http-equiv="refresh" content="0;INSERTSLIDEURL">' > $slidesprefix-$PROGLANG.html
echo '<a target="_blank" href="INSERTSLIDEURL">Google Slides generated INSERTTIMESTAMP<\/a>' >> $slidesprefix-$PROGLANG.html
timestamp=$(date +%c)
$SED -i -e "s/INSERTTIMESTAMP/$timestamp/" $slidesprefix-$PROGLANG.html
$SED -i -e "s/INSERTSLIDEURL/https:\/\/docs.google.com\/presentation\/d\/$id/" $slidesprefix-$PROGLANG.html
fi
else
echo WARNING: $slidesmd failed preprocessing
fi
else
echo WARNING: Lesson \'$LESSON\' doesn\'t have $slidesmd
fi
cd ../../..
done