#!/bin/bash
#
# Inital Setup see:
#    https://asciidoctor.org/docs/asciidoctor-revealjs/

SRCFILE=presentation.adoc
# ASCIIDOCTOR_REVEALJS="bundle exec asciidoctor-revealjs"
ASCIIDOCTOR_REVEALJS="/home/tobias/asciidoctor-revealjs-linux"

trap cleanup EXIT

function cleanup() {
    echo "** Trapped EXIT cleaining up";
    kill $(jobs -p)
}

echo "Rendering $SRCFILE"
$ASCIIDOCTOR_REVEALJS $SRCFILE

echo "Starting Webserver on :8000"
python3 -m http.server &

echo "Watching *.adoc for changes"
inotifywait -m -e close_write *.adoc |
while read events; do
  echo $events
  $ASCIIDOCTOR_REVEALJS $SRCFILE
done
