-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.sh
executable file
·96 lines (69 loc) · 1.8 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
#!/bin/sh
# check depencencies
MD_BUILD=markdown
$MD_BUILD --version | grep discount > /dev/null
if [ $? -ne 0 ]
then
echo "markdown --version did not match discount."
exit 1
fi
envsubst --version > /dev/null
if [ $? -ne 0 ]
then
echo "could not find envsubst."
exit 1
fi
# cleanup generated content
rm -f *.html
rm -f *.bak
ALL_MD="$(echo *.md | sort)"
export TOC="index.html"
# I need to keep track of "next" and "previous"
# so I have this ugly loop
PREV_MD=""
MD=""
FOR_ITERATION="$ALL_MD noop"
for NEXT_MD in $FOR_ITERATION
do
if [ ! -z "$MD" ]
then
BASE="$(basename $MD .md)"
TARGET="$BASE.html"
export TITLE="$(head -n 1 $MD)"
if [ "$NEXT_MD" = "noop" ]
then
export NEXT=""
else
export NEXT="$(basename $NEXT_MD .md).html"
fi
if [ -z "$PREV_MD" ]
then
export PREVIOUS=""
else
export PREVIOUS="$(basename $PREV_MD .md).html"
fi
cat template/prefix.html | envsubst >> $TARGET
cat template/page_prefix.html | envsubst >> $TARGET
$MD_BUILD -f toc -f footnote $MD >> $TARGET
cat template/page_prefix.html | envsubst >> $TARGET
cat template/suffix.html | envsubst >> $TARGET
fi
PREV_MD=$MD
MD=$NEXT_MD
done
# index page
export TITLE="Efficient Programming with Components"
export NEXT="00_foreword.html"
export PREVIOUS=""
TARGET="index.html"
cat template/prefix.html | envsubst >> $TARGET
cat template/page_prefix.html | envsubst >> $TARGET
cat template/cover.html >> $TARGET
# fill with table of contents
for MD in $ALL_MD
do
BASE=$(basename $MD .md)
$MD_BUILD -n -T -f toc -f footnote $MD | sed "s/href=\"#/href=\"${BASE}.html#/g" >> $TARGET
done
cat template/page_prefix.html | envsubst >> $TARGET
cat template/suffix.html | envsubst >> $TARGET