-
Notifications
You must be signed in to change notification settings - Fork 1
/
markdeck
executable file
·351 lines (321 loc) · 9.04 KB
/
markdeck
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/bin/bash
# combined script that includes the docker-compose configuration
set -ue
BUILD=deck
VERSION=0.52.4
PORT=${MARKDECK_PORT:-8080}
FRIENDS_PORT=$((${PORT} + 1))
export COMPOSE_PROJECT_NAME=$(basename $PWD)
calcUser() {
local dir="$1"
if stat -c %U "$dir" > /dev/null 2>&1; then
stat -c %U "$dir"
else
stat -f %Su "$dir"
fi
}
calcUserIdAndGroupId() {
local dir="$1"
if stat -c %U "$dir" > /dev/null 2>&1; then
stat -c %u:%g "$dir"
else
stat -f %u:%g "$dir"
fi
}
printHelp () {
echo "$(basename "$0") [-h|--help|-v|--version] [command]"
echo
echo "Commands:"
echo -e "\tstart: start markdeck server in the current folder (default)"
echo -e "\tstop: stop markdeck server"
echo -e "\tpull: pull docker images (this only has to happen once, at the start it will happen automatically)"
echo -e "\tupdate: update markdeck executable"
echo -e "\tscaffold: create an example presentation in the current folder"
}
printVersion () {
echo "$(basename "$0") v${VERSION}"
}
testOwnership () {
local dir="$1"
if [ $(calcUser "${dir}") != "${USER}" ]; then
echo "[ERR] The output folder '${dir}' MUST be owned by you!" 1>&2
echo "[ERR] Please change ownership to yourself ('sudo chown ${USER} ${dir}'), or" 1>&2
echo "[ERR] remove '${dir}' completely ('sudo rm -rf ${dir}')." 1>&2
exit 1
fi
}
createFolder () {
mkdir -p "${1}"
}
createComposeFile () {
tmpfile=$(mktemp)
cat > "${tmpfile}" << EODCF
version: "3.4"
services:
markdeck:
image: arne/markdeck-pandoc:0.52.4
user: "\$MARKDECK_USER"
environment:
- ONCE
volumes:
- type: bind
source: ${PWD}/
target: /source
read_only: true
- type: bind
source: ${PWD}/${BUILD}
target: /target
web:
image: arne/markdeck-liveserver:0.2
ports:
- ${PORT}:8080
volumes:
- type: bind
source: ${PWD}/${BUILD}
target: /target
read_only: true
depends_on:
- markdeck
a2sketch:
image: arne/a2sketch:0.13
volumes:
- type: bind
source: ${PWD}/a2s-custom-types
target: /custom-types
read_only: true
pdf:
image: arne/markdeck-decktape:0.10
volumes:
- type: bind
source: ${PWD}/${BUILD}
target: /slides
shm_size: 1G
depends_on:
- markdeck
- web
standalone:
image: arne/markdeck-standalone:0.5
volumes:
- type: bind
source: ${PWD}/${BUILD}
target: /slides
depends_on:
- web
friends:
image: arne/markdown-friends:0.5
ports:
- ${FRIENDS_PORT}:8081
EODCF
echo "${tmpfile}"
}
dockerCompose () {
composefile="$(createComposeFile)"
# trap "rm -f '${composefile}'; exit" EXIT SIGHUP SIGTERM SIGINT SIGKILL SIGQUIT
docker-compose -f "${composefile}" "${@}"
}
update () {
curl -# -S -f -L -o "${0}" https://raw.githubusercontent.com/arnehilmann/markdeck/master/markdeck
chmod a+x "${0}"
echo "Updated from $(printVersion) to $("${0}" --version)."
}
scaffold () {
if ! isPresentationFolder; then
mkdir -p assets/css
if [ ! -e slides.md ]; then
echo "Creating slides.md."
cat > slides.md << "EOF"
---
title: markdeck scaffold
pdf: markdeck-scaffold.pdf
slideNumber: true
controls: true
---
# first slide {bg=#eee}
made with [markdeck](https://arnehilmann.github.io/markdeck/){target="_blank"}
```render_a2s
#----------.
|[markdeck]|
'----------#
[markdeck]: {"fill": "Teal", "fillStyle": "solid"}
```
<small>
interesting links:
[your main deck](/){target="_parent"}
• [markdown/slide side-by-side](/explain.html)
• [utilities](//localhost:8081/){target="_blank"}
</small>
⚪ ⚪ ⚪
EOF
fi
if [ ! -e assets/explain.html ]; then
echo "Creating assets/explain.html."
cat > assets/explain.html << "EOF"
<html>
<head>
<style>
body {
margin: 0;
}
.box {
display:inline-block;
padding: 0;
}
.deck {
width: 60%;
}
.source {
width: 38%;
border-left: 4px dashed #ccc;
}
</style>
</head>
<body>
<div class="box deck">
<iframe
id="deck"
src="index.html?in_explain"
style="border: 0;"
frameborder="0"
scrolling="no" height="100%" width="100%" align="left" ></iframe>
</div>
<div class="box source">
<iframe
id="source"
src="slides.combined.md.txt"
frameborder="0"
height="100%" width="100%" align="left" ></iframe>
</div>
<script>
var deck = document.getElementById('deck');
var source = document.getElementById('source');
var split_source = function(doc) {
// console.log(doc);
var myText = doc.getElementsByTagName("pre")[0];
// console.log(myText);
var lines = myText.innerHTML.split("\n");
var numLines = lines.length;
var i;
var currentSection = undefined;
var header = false;
window.sections = Array();
for (i = 0; i < numLines; i++) {
var line = lines[i];
// console.log("line: " + line);
if (line.indexOf('---') == 0) {
header = !header;
continue;
}
if (header) {
continue;
}
if (line.indexOf('# ') == 0) {
if (currentSection) {
window.sections.push(currentSection.join("\n"));
}
// console.log("slide header found: " + line);
currentSection = Array();
currentSection.push('<pre>');
currentSection.push(line);
} else {
if (currentSection) {
currentSection.push(line);
}
}
}
window.sections.push(currentSection.join("\n"));
console.log(window.sections);
}
document.getElementById('deck').onload = function(event) {
var sourceDoc = source.contentDocument;
split_source(sourceDoc.documentElement);
var deckWindow = deck.contentWindow;
var update_source = function() {
// console.log("updating source view");
var slideNr = deckWindow.Reveal.getIndices().h;
source.contentDocument.documentElement.innerHTML = '<div style="padding-left: 1em; position: relative; top: 50%; transform: translateY(-50%);"><em>slide source</em></br></br>' + window.sections[slideNr] + "</div>";
};
update_source();
deckWindow.Reveal.addEventListener('slidechanged', update_source);
deckWindow.focus();
};
</script>
</body>
</html>
EOF
fi
if [ ! -e assets/css/slides.scss ]; then
echo "Creating assets/css/slides.scss."
cat > assets/css/slides.scss << "EOF"
/* put your styles in this file */
EOF
fi
echo "Yay, go ahead and create you presentation!"
echo "Write the slides in slides.md."
echo "Store images and styles in assets/."
echo "Run '$(basename "${0}")' to compile the presentation."
else
echo "No scaffolding needed, there's already a presentation in this folder (slides.md)."
echo "Run '$(basename "${0}")' to compile the presentation."
return 1
fi
}
isPresentationFolder () {
shopt -s nullglob
res=1
[ -n "$(echo ${1:-.}/slide*.md)" ] && res=0
shopt -u nullglob
return $res
}
startMarkdeck () {
if ! isPresentationFolder; then
echo "This folder doesn't contain a markdeck presentation." 1>&2
echo "Run '$(basename "${0}") scaffold' to create one." 1>&2
return 1
fi
createFolder "${BUILD}"
testOwnership "${BUILD}"
MARKDECK_USER=$(calcUserIdAndGroupId "${BUILD}") dockerCompose up --abort-on-container-exit --remove-orphans
}
if [ $# -ge 1 ]; then
case "${1}" in
'scaffold' )
scaffold
;;
'pull' )
dockerCompose pull
;;
'stop' )
dockerCompose down
;;
'update' )
update
;;
'-h' | '--help' )
printHelp
;;
'-v' | '--version' )
printVersion
;;
'start' )
startMarkdeck
;;
'dev' )
dockerCompose up
;;
'once' )
MARKDECK_USER=$(calcUserIdAndGroupId "${BUILD}") ONCE=true \
dockerCompose up \
--abort-on-container-exit \
--exit-code-from markdeck \
-t 1 \
markdeck a2sketch
;;
* )
printHelp
exit 1
;;
esac
else
startMarkdeck
fi
exit $?