#!/usr/bin/env bash

rm -rf build

mkdir build

python3 identify.py

for i in 20*.org; do
    echo Exporting $i
    emacs --batch -l pre.el $i -l export.el -f org-html-export-to-html --kill
done

for i in *.html; do
    thebase="${i%%.*}"
    dirname=${thebase//"-"/}
    mkdir build/$dirname
    mv $i build/$dirname/index.html
done

mv readme.org tempfile

for i in *.org; do
    rm -f $i
done

mv tempfile readme.org

rclone copy build prazevps:/var/www/tre/public/notes -P

current_date=$(date +"%Y%m%d")
curl -i -d "source=https://tre.praze.net/notes/$current_date&target=https://fed.brid.gy/" https://fed.brid.gy/webmention