diff --git a/fedi2html.sh b/fedi2html.sh index 0525396..7122a96 100755 --- a/fedi2html.sh +++ b/fedi2html.sh @@ -80,6 +80,8 @@ POST_TEMPLATE=' ' +EMOJI_TEMPLATE='$EMOJI_SHORTCODE' + replace_emojis() { local post_data="$1" local emojis="$(echo "$post_data" | jq -r '.emojis[]|(.url + "\t" + .shortcode)')" @@ -89,15 +91,25 @@ replace_emojis() { cat > "$temp" for line in $emojis; do - local url="$(echo "$line" | awk '{print $1}')" - local shortcode="$(echo "$line" | awk '{print $2}')" - sed -i "s%:${shortcode}:%\"${shortcode}\"%g" \ - "$temp" + local EMOJI_URL="$(echo "$line" | awk '{print $1}')" + local EMOJI_SHORTCODE="$(echo "$line" | awk '{print $2}')" + local value="$(env_subst "$EMOJI_TEMPLATE")" + sed -i "s%:${EMOJI_SHORTCODE}:%${value}%g" "$temp" done cat "$temp" rm "$temp" } +prep_template() { + local template="$1" + echo "$template" \ + | sed 's%\"%\\\"%g' +} + +env_subst() { + local template="$1" + eval "echo \"$(prep_template "$template")\"" +} render_post() { local post_data="$1" @@ -108,8 +120,6 @@ render_post() { local POST_URL="$(echo "$post_data" | jq -r .url)" local POST_DATE="$(echo "$post_data" | jq -r .created_at)" local POST_CONTENT="$(echo "$post_data" | jq -r .content | replace_emojis "$post_data")" - eval "echo \"$(echo "$POST_TEMPLATE" | sed 's%\"%\\\"%g')\"" + env_subst "$POST_TEMPLATE" } - -