#!/bin/bash

# This script generates the HTML version of the User Guide
# for the txt2tags website.

cd $(dirname "$0")

outdir="../../../website/userguide/"

# Regenerate HTML version (if needed)
test userguide.t2t -nt userguide.html && txt2tags userguide.t2t

# HTMLDOC splits the one-big-HTML-file to lots of tiny HTML files
htmldoc --book --no-title \
	--toclevels 2 --toctitle "Txt2tags User Guide" \
	-t htmlsep \
	-d "$outdir" \
	userguide.html

cd "$outdir" || { echo "Can't find $outdir, aborting." ; exit 1; }

# Append CSS file call to the HEAD of each HTML file
for file in *.html
do
	cp "$file" tmp
	sed 's|</HEAD>|<LINK REL="stylesheet" TYPE="text/css" HREF="userguide.css"></HEAD>|' tmp > "$file"
done
rm tmp


echo "User Guide generated at $outdir"
exit 0
