#!/bin/bash

# build the files for tuhh-delivery locally
#
#  Structure 
#
# tuhh-build/
# ├── forschung
# │   ├── aa/forschung.html
# │   ├── cm/forschung.html
# │   ├── dm/forschung.html
# │   ├── nm/forschung.html
# │   └── st/forschung.html
# ├── home
# │   ├── ataraz.html
# │   ├── cseifert.html
# │   └── ymogge.html
# └── topics
#     ├── img
#     │   ├── BO_BDO.jpg
#     │   ├── controlimex.png
#     │   └── webpage-example.png
#     ├── topic.html
#     └── Zemke_Hessenberg.html
# 
#
#

RESEARCH_BIN=$RESEARCH_ROOT/bin
RESEARCH_STATIC=$RESEARCH_ROOT/static
RESEARCH_BUILD=$RESEARCH_ROOT/build
RESEARCH_DEPLOY=$RESEARCH_ROOT/build-tuhh

rm -rf $RESEARCH_BUILD $RESEARCH_DEPLOY
mkdir -p $RESEARCH_BUILD $RESEARCH_DEPLOY 

echo "Preproc Topics"
$RESEARCH_BIN/preproc_topics.sh "$RESEARCH_BUILD" \
                                "$RESEARCH_ROOT/topics" \
                                "$RESEARCH_BUILD/home" \
                                "$RESEARCH_BUILD/forschung" 
                                #>> $RESEARCH_BUILD/build.log 2>&1

# build html files
echo "Creating HTML Files with pandoc"
#topics
$RESEARCH_BIN/create_html.sh $RESEARCH_DEPLOY/forschung/topics \
                             $RESEARCH_BUILD \
                             TUHH #>> $RESEARCH_BUILD/build.log 2>&1
#staffpages
$RESEARCH_BIN/create_html.sh $RESEARCH_DEPLOY/home \
                             $RESEARCH_BUILD/home \
                             TUHH #>> $RESEARCH_BUILD/build.log 2>&1
# wg pages 
for wg in aa cm dm nm st
do
    $RESEARCH_BIN/create_html.sh $RESEARCH_DEPLOY/forschung/$wg \
                                 $RESEARCH_BUILD/forschung/$wg \
                                 TUHH #>> $RESEARCH_BUILD/build.log 2>&1
done

cp -r $RESEARCH_ROOT/img $RESEARCH_DEPLOY/forschung/topics
#$RESEARCH_BIN/create_html.sh $RESEARCH_BUILD/snippets

# replace markers
#echo "Replacing markers"
#$RESEARCH_BIN/replace_marker.sh $RESEARCH_BUILD 

#make public directory and copy files
#mkdir -p $RESEARCH_DEPLOY/.public
#for f in $RESEARCH_BUILD/*_final.html
#do
#    filename=$(basename -- "$f")
#    cp $f $RESEARCH_DEPLOY/.public/${filename%_final.html}.html
#done
#
#echo "Copying files to final destination ..."
#cp -r $RESEARCH_ROOT/{img,css}  $RESEARCH_DEPLOY/.public
#mv -v $RESEARCH_DEPLOY/.public  $RESEARCH_DEPLOY/public
#
#echo "Done. Visit file://$RESEARCH_DEPLOY/public/index.html ."
