#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
cd ../

mkdir -p public

cat workflow/vendor/org.css workflow/workflow.css > public/styles.css

sed -e '/^\* Tasks$/,/^\* Improvements$/!d' TODOs.org | \
  head -n -1                                          | \
  cat workflow/preamble.org - > tasks-and-bugs.org

emacs tasks-and-bugs.org                               \
      -l workflow/vendor/htmlize.el                    \
      --eval '(setq org-export-allow-bind-keywords t)' \
      -f org-html-export-to-html                       \
      --batch                                          \
      --kill

# Add anchor link to bug headers
perl -pe \
     's|^<h3 id="(.*?)">(.*)</h3>$|<h3 id="\1">\2<br /><a class="header-anchor" href="#\1">#\1</a></h3>|' \
     tasks-and-bugs.html > public/tasks-and-bugs.html
