Skip to content

Commit

Permalink
chore: fix SVG generation script
Browse files Browse the repository at this point in the history
closes #764
  • Loading branch information
PaulRBerg committed Dec 21, 2023
1 parent 5e2f91c commit c1a7fe5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions shell/generate-svg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Pre-requisites:
# - foundry (https://getfoundry.sh)
# - sd (https://github.com/chmln/sd)

# Strict mode: https://gist.github.com/vncsna/64825d5609c146e80de8b1fd623011ca
set -euo pipefail
Expand All @@ -24,11 +25,16 @@ output=$(
"$arg_amount" \
"$arg_duration"
)
svg=$(echo "$output" | awk -F "svg: string " '{print $2}' | awk 'NF > 0')

# Forge adds 'svg: string ' as a prefix before the SVG
# - The awk command records everything after the prefix, while filtering out empty lines
# - `sd \\"` '"'` removes the escape backslashes
# - `sd ^\"|\"$' ''` removes the starting and the ending double quotes
svg=$(echo "$output" | awk -F "svg: string " '/svg: string /{print $2; exit}' | sd '\\"' '"' | sd '^"|"$' '')

# Generate the file name
name="nft-${arg_progress}-${arg_status}-${arg_amount}-${arg_duration}.svg"
sanitized="$(echo "$name" | sed "s/ //g" )" # remove whitespaces
sanitized="$(echo "$name" | sd ' ' '' )" # remove whitespaces

# Put the SVG in a file
mkdir -p "out-svg"
Expand Down

0 comments on commit c1a7fe5

Please sign in to comment.