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

set -eu

input=$1
parameters=$2
template=$3
output=$4

cp ${template} ${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
    spath=$(realpath --relative-to $(dirname "${input}") stylesheets/"${s}".css)
    link_template='<link rel="stylesheet" href="%s">\n'
    link_stylesheets+=$(printf "${link_template}" "${spath}")
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}