Repository navigation
Expand file tree
/
Copy pathloop
More file actions
executable file
·170 lines (148 loc) · 5.27 KB
/
Copy pathloop
File metadata and controls
executable file
·170 lines (148 loc) · 5.27 KB
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
#!/bin/bash
set -e -E -u
PORT=8080
PORT_HELPER=8081
ONCE=false
PARAM=${1:-loop}
case $PARAM in
shell) bash -i; exit;;
--once) ONCE=true;;
loop) ;;
*) echo "unknown parameter '$PARAM' given, aborting here..." && exit 1;;
esac
shopt -s nullglob
esc=$(printf '\033')
function print_usage() {
echo -e "\n\n\n${esc}[1mmarkdeck $VERSION - $MOTTO${esc}[0m\n"
echo -e " ${esc}[1mfor the slides: open http://localhost:$PORT${esc}[0m"
echo
echo -e "for side-by-side view: open http://localhost:$PORT/explain.html"
echo -e " to stop markdeck: hit Ctrl-C"
echo
echo
}
function show_errors() {
rm -f /target/index.html
echo '<html><head></head><body><pre>' > /target/index.html
cat /tmp/pandoc.output >> /target/index.html
echo '</pre></body></html>' >> /target/index.html
echo -e "${esc}[37m${esc}[43m"
echo -e "\npandoc crashed\n"
cat /tmp/pandoc.output
echo -e "${esc}[0m"
sleep 4
}
if ! $ONCE; then
print_usage
touch /target/index.html
fi
[[ -e /source/render-asciiart-filter.config ]] && \
ASCIIART_CONFIG=/source/render-asciiart-filter.config || \
ASCIIART_CONFIG=/markdeck/lib/render-asciiart-filter.config
export ASCIIART_CONFIG
export ASCIIART_LIBDIR=/markdeck/lib
while true; do
cd /target
echo "-------- rerendering ---------"
mkdir -p /target/assets/css/
cp -v /markdeck/assets/markdeck/css/when-rerendering.css /target/assets/css/rerendering.css
[[ -d /target/rendered ]] || mkdir -p /target/rendered
echo "-------- rsync output --------"
rsync -a /markdeck/assets /target/ || :
touch /target/assets/css/slides.css /target/assets/css/render-pdf.css
[[ -d /source/assets ]] && rsync -av /source/assets /target/ || :
rsync -a /markdeck/explain.html /target/ || :
fc-list
echo "-------- /rsync output --------"
echo
echo "-------- sass output --------"
if [[ -e /source/assets/css/slides.scss ]]; then
sassc \
/source/assets/css/slides.scss \
/target/assets/css/slides.css || :
fi
if [[ -e /source/assets/css/slides.impress.scss ]]; then
sassc \
/source/assets/css/slides.impress.scss \
/target/assets/css/slides.impress.css || :
fi
sassc \
/markdeck/assets/markdeck/css/markdeck.revealjs.scss \
/target/assets/markdeck/css/markdeck.revealjs.css || :
sassc \
/markdeck/assets/markdeck/css/markdeck.impressjs.scss \
/target/assets/markdeck/css/markdeck.impressjs.css || :
echo "-------- /sass output --------"
echo
echo "-------- config --------"
shopt -s nullglob
SOURCE_MD=$(echo /source/slide*.md)
shopt -u nullglob
METADATA="$(pandoc --template=/markdeck/metadata.template ${SOURCE_MD:-/markdeck/note.md} /markdeck/defaults.yaml)"
mkdir -p /target/.meta/
rm -f /target/.meta/config.json
echo "$METADATA" > /target/.meta/config.json
jq '. | .' <<<$METADATA
variant=$(jq -r '.variant' <<< "$METADATA")
echo "ASCIIART_CONFIG=$ASCIIART_CONFIG"
echo "-------- /config --------"
echo
echo "-------- pandoc output --------"
PANDOC_ARGS=
[[ -e /source/include-before-body ]] && PANDOC_ARGS="$PANDOC_ARGS --include-before-body /source/include-before-body"
[[ -e /source/include-after-body ]] && PANDOC_ARGS="$PANDOC_ARGS --include-after-body /source/include-after-body"
rm -f /target/slides.combined.md.txt
# cat ${SOURCE_MD:-/markdeck/note.md} > /target/slides.combined.md.txt
if [[ -n ${SOURCE_MD:-} ]]; then
for F in $SOURCE_MD; do
markdown-pp --exclude latexrender $F >> /target/slides.combined.md.txt
echo >> /target/slides.combined.md.txt
done
else
cp /markdeck/note.md /target/slides.combined.md.txt
fi
template=/markdeck/template-${variant}.html
if pandoc \
-f markdown+yaml_metadata_block \
-t html5 \
--no-highlight \
--wrap=preserve \
--standalone \
--template=$template \
--section-divs \
--lua-filter /markdeck/lib/skip-slide-filter.lua \
--filter mathjax-pandoc-filter \
--lua-filter /markdeck/lib/render-asciiart-filter.lua \
--lua-filter /markdeck/lib/render-emojis-filter.lua \
--lua-filter /markdeck/lib/bg-shortcut-filter.lua \
--lua-filter /markdeck/lib/${variant}-shortcut-filter.lua \
--lua-filter /markdeck/lib/inline-svg.lua \
--lua-filter /markdeck/lib/font-awesome.lua \
$PANDOC_ARGS \
-o /target/index.html.tmp \
/target/slides.combined.md.txt /markdeck/defaults.yaml 2>&1 | tee /tmp/pandoc.output;
then
if [[ -e /target/index.html.tmp ]]; then
echo "" > /target/assets/css/rerendering.css
mv /target/index.html.tmp /target/index.html
else
show_errors
fi
else
show_errors
fi
echo "-------- /pandoc output --------"
echo
echo "-------- /rerendering ----------"
echo
$ONCE && break
if [[ /source -nt /target/index.html ]]; then
echo -e "\n\n\nchange detected: sources newer than rendered deck, rerendering started...\n\n\n"
continue
fi
sleep .5
print_usage
/markdeck/wait-for-changes
echo -e "\n\n\n\n\n\n\n\n\n\n"
done
echo "done."