#! /bin/bash
set -o pipefail

echo '> copy outer HTML of html just inside iframe' >&2

font_family="$(cat resume.html | grep -o 'font-family[^;]*' | tail -n 1 | awk '{print $NF}')"
cat resume.html \
   | sed 's/>...<\/text/> - <\/text/g' \
   | sed 's/overflow: hidden;/margin: auto !important; padding-bottom: .0em !important;/g' \
   | sed 's/padding: 0px 60pt;/padding: 0px 18pt;/' \
   | sed 's/width: 612pt;/width: 512pt;/' \
   | sed "s#<link [^>]*as=\"font\"[^>]*/fonts/[^${font_family:0:1}][^>]*>##g"  \
   | sed "s#<link [^>]*as=\"font\"[^>]*/fonts/${font_family:0:1}[^${font_family:1:1}][^>]*>##g"  \
   | sed "s#/fonts/#./fonts/#g" \
   > resume.html.2 \
|| rm resume.html.2

for font_file in $(
   cat resume.html.2 \
   | grep -o 'href="./fonts/[^"]*' \
   | sed 's#.*"./##'
); do
   if [ ! -f "$font_file" ]; then
      mkdir -p ./${font_file%/*}/
      curl -sS -L https://www.open-resume.com/$font_file > $font_file
   fi
done


#   | sed 's#"/fonts/#"https://www.open-resume.com/fonts/#g' \


   #| sed 's/margin-top: 15pt;/margin-top: 20pt;/g' \
   #| sed 's/margin-top: 12pt;/margin-top: 17pt;/g' \
   #| sed 's/margin-top: 8pt;/margin-top: 12pt;/g' \
   #| sed 's/margin-top: 6pt;/margin-top: 10pt;/g' \

