blob: 358680184bf697555a3b9868b54436736d7cccb0 (
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
55
56
57
58
59
60
61
62
63
64
|
#!/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
iconcolor=
. ${parameters}
sed -i s/'{TITLE}'/"${title}"/ ${output}
link_stylesheets=''
for s in "${stylesheets[@]}"
do
# Prefer relative paths so that drafts under /admin/drafts find
# the correct stylesheets.
# ${input} might be a temporary file; assume ${template} is a
# bona-fide node in our directory hierarchy, and use that to
# compute the path to the stylesheets folder.
spath=$(realpath --relative-to $(dirname "${template}") 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}
sed -i s/'{TRANSLATION}'/"${translation}"/ ${output}
for transform in "${transforms[@]}"
do
sed -i "${transform}" ${output}
done
if test "${iconcolor}"
then
sed -i s/'{ICONCOLOR}'/"-${iconcolor}"/ ${output}
else
sed -i s/'{ICONCOLOR}'// ${output}
fi
sed -i -e /'{MAIN}'/"r ${input}" -e /'{MAIN}'/'c\' ${output}
${postprocess} ${output}
|