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
|
#!/bin/sh -eu
. ./config
title="${1:-$TITLE}"
content=$(cat)
awk \
-v title="$title" \
-v content="$content" \
-v header="$TEMP_HEAD" \
-v footer="$TEMP_FOOT" \
'
function replace(str, pat, rep, out, parts, n, i) {
n = split(str, parts, pat)
out = parts[1]
for (i = 2; i <= n; i++)
out = out rep parts[i]
return out
}
BEGIN {
while ((getline line < header) > 0) hbuf = hbuf line "\n"
close(header)
while ((getline line < footer) > 0) fbuf = fbuf line "\n"
close(footer)
}
{
line = $0
line = replace(line, "{{TITLE}}", title)
line = replace(line, "{{CONTENT}}", content)
line = replace(line, "{{HEADER}}", hbuf)
line = replace(line, "{{FOOTER}}", fbuf)
print line
}' "$TEMP_PAGE"
|