#!/bin/bash
# Generate web pages from the content files under this script's enclosing directory
# bash trick to obtain a clean absolute path to this script.
pushd $(dirname $0) >/dev/null
SCRIPTPATH=$(pwd -P)
popd >/dev/null
SCRIPTDIRNAME=$(basename ${SCRIPTPATH})
MYPROGNAME=$(basename $0)
set -e
MAKEPAGES="/usr/local/bin/makepages"
BASEDIR=${SCRIPTPATH}
MYRESOURCES="images videos certificates configscripts"
## regenerate certificates, configscripts and view markdown files
CERTSSH="/usr/local/bin/certssh"
pushd ${BASEDIR} >/dev/null
# These will be regenerated
rm -f content/certificates/*  content/configscripts/*
rm -f content/parts/userview.md content/parts/authview.md content/parts/adminview.md
${CERTSSH} publish -r
popd >/dev/null
## end regenerate
pushd ${SCRIPTPATH}/content/pages >/dev/null
# list of content/pages/*.json as basenames without the extension
# code these names explicitly if you want to change the order of the buttons
MYPAGES=$(ls *.json | sed -e 's/\..*$//')
CWD=$(pwd)
(>&2 echo ${MYPROGNAME}: CWD: ${CWD})
(>&2 echo ${MYPROGNAME}: pages: ${MYPAGES})
popd >/dev/null
pushd ${SCRIPTPATH} >/dev/null
mkdir -p output
${MAKEPAGES} rebrand -b default_brand.json -p content/pages
${MAKEPAGES} generate -b content -O output -r ${MYRESOURCES} -e -B -p ${MYPAGES}
${MAKEPAGES} transcode -v output/videos -s
popd >/dev/null
