#!/bin/bash -xe
mkdir -p public

cat << EOF > PAGES
PAGES_URL =  $PAGES_URL
PAGES_SLUG = $PAGES_SLUG
GITLAB_USER = $GITLAB_USER
PROJECT_BRANCH = $PROJECT_BRANCH
GITLAB_HOST = $GITLAB_HOST
PROJECT_REPO = $PROJECT_REPO
EOF

echo "**** Updating $PAGES_URL/$VER_DIR ****"
echo "**** env ****"
env

# Clean build directory
make clean BUILDDIR=public

# Render HTML
make html BUILDDIR=public
mv public/html/* public/

# Render PDF
make latexpdf BUILDDIR=public/
mv public/latex/*.pdf public/

# Cleanup
echo "**** cleanup ****"
rm -rf public/doctrees
rm -rf public/latex