summaryrefslogtreecommitdiff
path: root/build.sh
blob: ee479de7adb1ea32acf31fd48b7ec30b5cc37905 (plain)
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
#!/bin/bash

set -eu

input=$1
output=$2

parameters=${input/%.html/.sh}

if ! test -f ${parameters}
then
    cp ${input} ${output}
    exit
fi

cp template.html ${output}

transform-li-current-a ()
{
    local old="<li><a href=\"$1.html\">"
    local new="<li><a class=\"current\" href=\"$1.html\">"
    echo "s/${old}/${new}/"
}

transform-li-dropdown-current-a ()
{
    local old="<li class=\"dropdown\"><a href=\"$1.html\">"
    local new="<li class=\"dropdown\"><a class=\"current\" href=\"$1.html\">"
    echo "s/${old}/${new}/"
}

transforms=()
postprocess=true
. ${parameters}

sed -i s/'{TITLE}'/"${title}"/ ${output}

link_stylesheets=''
for s in "${stylesheets[@]}"
do
    link_template='<link rel="stylesheet" href="stylesheets/%s.css">\n'
    link_stylesheets+=$(printf "${link_template}" "${s}")
done

sed -i /'{STYLESHEETS}'/'c\'"${link_stylesheets}" ${output}

for transform in "${transforms[@]}"
do
    sed -i "${transform}" ${output}
done

sed -i -e /'{MAIN}'/"r ${input}" -e /'{MAIN}'/'c\' ${output}

${postprocess} ${output}