diff --git a/build.sh b/build.sh
index 279ad53..4e5031b 100755
--- a/build.sh
+++ b/build.sh
@@ -9,9 +9,9 @@ mkdir dist&&cd dist
cp ../style.css .
for file in $(du -a ../src/ | cut -f2 | grep -E '.md$'); do
target="$(echo $file | source_to_target)"
- content="$(pandoc --from markdown+emoji --wrap=none -i $file | sed -e 's/[]\/$*.^[]/\\&/g' | escape_newlines )" # To escape the string for sed later on
- prefix=$(realpath --relative-to $(dirname $target) .)
- sidebar=$(for x in ../src/**/*.md; do echo "
$(realpath --relative-to ../src/ $x | sed -e 's/.md$//')" | sed -e 's/[]\/$*.^[]/\\&/g' | escape_newlines; done)
+ export CONTENT="$(pandoc --from markdown+emoji --wrap=none -i $file)"
+ export PREFIX=$(realpath --relative-to $(dirname $target) .)
+ export SIDEBAR=$(for x in ../src/**/*.md; do echo "$(realpath --relative-to ../src/ $x | sed -e 's/.md$//')"; done)
mkdir -p $(dirname $target)
- cat ../template.tpl | sed -e "s/{CONTENT}/$content/" -e "s:{PREFIX}:$prefix:" -e "s/{SIDEBAR}/$sidebar/" > $target
+ cat ../template.tpl | awk -f ../template.awk | bash > $target
done
diff --git a/template.awk b/template.awk
new file mode 100644
index 0000000..46fb94b
--- /dev/null
+++ b/template.awk
@@ -0,0 +1,22 @@
+# escaped lines
+/^[ \t]*%/ {
+ i = index($0, "%");
+ print substr($0, i+1, length($0)-i);
+ next;
+}
+
+# inline code
+/%\(.*%\)/ {
+ gsub(/'/, "\\'", $0);
+ gsub(/%\(.*%\)/, "';echo -n &;echo '", $0);
+ gsub(/%\(/, "", $0);
+ gsub(/%\)/, "", $0);
+ printf("echo -n '%s'\n", $0);
+ next;
+}
+
+{
+ gsub(/'/, "\\'", $0);
+ printf("echo '%s'\n", $0);
+}
+
diff --git a/template.tpl b/template.tpl
index f4102b0..b6104b9 100755
--- a/template.tpl
+++ b/template.tpl
@@ -2,7 +2,7 @@
Jocelyn Otto
-
+
@@ -12,11 +12,11 @@
- {CONTENT}
+ % echo $CONTENT