#!/bin/bash

SITE_NAME="WickedDocs"

CLEAN_MODE=0
if [ "$1" == "--clean" ]
then
	CLEAN_MODE=1
	echo "Cleaning..."
	rm *~
fi

ApplyTemplates()
{
	TITLE="$1"
    SUB_TITLE="$2"
	PAGE_BASENAME="$3"
	if [ "$CLEAN_MODE" != "1" ]
	then
	  # This next command makes it possible for variable expansion to happen when applying the header
	  echo `eval $'cat <<\002\n'"$(<tmpl/header.htm)"$'\n\002'` > $PAGE_BASENAME.html
	  # The way this does the echo of the cat command causes the white space to be removed
	  cat pages/$PAGE_BASENAME.htm tmpl/footer.htm >> $PAGE_BASENAME.html
	  # | sed -e "s/^[ \t]*//g" -e ":a;N;$!ba;s/\n//g" 
	else
	  rm $PAGE_BASENAME.html
	fi
}

ApplyTemplates  "About"         "" index
ApplyTemplates  "Downloads"     "" download
ApplyTemplates  "Features"      "" features
ApplyTemplates  "Screenshots"   "" screenshots
ApplyTemplates  "News"          "" news
ApplyTemplates  "Documentation" "" documentation
ApplyTemplates  "Help"          "" help
ApplyTemplates  "Support"       "" support
ApplyTemplates  "F.A.Q."        "Frequently Asked Questions" faq
ApplyTemplates  "Community"     "" community
ApplyTemplates  "Registration"  "" register
ApplyTemplates  "Contact"       "" contact
ApplyTemplates  "Legal"         "" legal

