diff --git a/fedi2html.sh b/fedi2html.sh
index 1dcb364..0525396 100755
--- a/fedi2html.sh
+++ b/fedi2html.sh
@@ -82,29 +82,20 @@ POST_TEMPLATE='
replace_emojis() {
local post_data="$1"
- local emojis="$2"
+ local emojis="$(echo "$post_data" | jq -r '.emojis[]|(.url + "\t" + .shortcode)')"
+ local temp="$(mktemp)"
+ local IFS="
+"
+ cat > "$temp"
- # So, this function is recusive; in hindsight, it didn’t have to be. oh well!
- if test -n "$post_data" -a -z "$emojis"; then
- # Init case; start subsitutions in next level of recursion
- replace_emojis \
- "" \
- "$(echo "$post_data" \
- | jq -r '.emojis[]|(.url + "\t" + .shortcode)')"
- elif test -n "$emojis"; then
- # Substitute the current emoji (first line of $emojis)
- local url="$(echo "$emojis" | head -1 | awk '{print $1}')"
- local shortcode="$(echo "$emojis" | head -1 | awk '{print $2}')"
-
- sed "s%:${shortcode}:%%g" \
- | replace_emojis \
- "" \
- "$(echo "$emojis" | tail +2)"
- else
- # End-case; $emojis is empty, so our job is done.
- # Just print the results.
- cat
- fi
+ for line in $emojis; do
+ local url="$(echo "$line" | awk '{print $1}')"
+ local shortcode="$(echo "$line" | awk '{print $2}')"
+ sed -i "s%:${shortcode}:%%g" \
+ "$temp"
+ done
+ cat "$temp"
+ rm "$temp"
}