blob: 7b214314f81018c83e46c574159ad18079ac6fd9 (
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
|
#!/bin/bash
# Path to directory where this script is
# https://stackoverflow.com/a/246128/98600
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# Render txt2tags into html file
# Arguments:
# 1. txt2tags source file, e.g. download/index.t2t
# 2. html target filen, e.g. download/index.html
function render_html {
t2t=$1
html=$2
relroot="$( dirname $t2t | sed -E 's/^.\///' | sed -E 's/[^/]+/../g' )"
pandoc \
--from=t2t \
--to=html5 \
--standalone \
--template="$DIR/_template.html" \
--variable="rel-root:$relroot" \
"$t2t" \
--output="$html"
if [ -f "$html" ] ; then
sed -i.bak "s/<table>/<table class=\"table\">/" "$html" && rm "$html.bak"
sed -i.bak -E "s/\`\`(.+)\`\`/<code>\1<\/code>/g" "$html" && rm "$html.bak"
echo "$html"
else
echo "Error creating $html"
fi
}
if [ $# -gt 0 ] ; then
# Render specific file(s) from args, ignoring dates
for t2t in "$@" ; do
html="${t2t%.t2t}.html"
render_html "$t2t" "$html"
done
else
# Render all files found in cwd, and below, if source is newer
find . -name '*.t2t' | while read t2t ; do
html="${t2t%.t2t}.html"
if [ "$t2t" -nt "$html" ] ; then
render_html "$t2t" "$html"
fi
done
fi
|