#!/bin/zsh
set -e
set -x
USER=lucky
HOST=luckymeowth.gg
DIR=www   # might sometimes be empty!

zola build
pushd public

rg -l -t html "\\$" | xargs deno run --allow-read --allow-write ../themes/lucky/scripts/katexRender.ts
rg -l -t html "ptcg" | xargs deno run --allow-read --allow-write ../themes/lucky/scripts/ptcgIcons.ts

fd -e html -x minify-html --keep-html-and-head-opening-tags --do-not-minify-doctype --minify-js -o {} {}
fd -e xml -x minify-html -o {} {}
fd -e css -x minify-html -o {} {}
fd -e js -x minify-js -m global -o {} {}

popd
rsync -O -avzz --no-p --no-g --chmod=ugo=rwX public/ ${USER}@${HOST}:~/${DIR}
rm -rf public/

exit 0
