#!/bin/sh

template=${1:-index.html.in}

function dump_latest_changes () {
	git-rev-list  --max-count=10 --pretty HEAD |
	while read line; do
	    case $line in
		Date:*)
		    d=${line/??:??:??}	# Strip time
		    d=${d/Date:};	# Strip Date: prefix
		    d=${d/[+-]????}	# Strip timezone
		    if test "$d" != "$date"; then
			test "$date" && echo "</ul>"
			echo -e "<h2>$d</h2>\n<ul>"
		    fi
		    date=$d;;
		commit*);;
		Author*);;
		?*)
		    echo "<li>$line";;
	    esac
	done
	echo "</ul>"
}

cat $template |
while read t; do
    case $t in
	"@LATEST_CHANGES@"*)
	    dump_latest_changes;;
	*)
	    echo $t;;
    esac
done
