#!/bin/sh
name=$(basename ${PWD%%/})
h=$(printf '%s' "$name" | sed 's/./#/g')

printf '%s\n%s\n%s\n\n' "$h" "$name" "$h"
printf '.. |date| date:: %s\n\n' '%Y-%m-%d %H:%M:%S %Z'
printf ':Revision: %s\n' "$(sed <.bzr/branch/last-revision 's/@/_at_/g;s/\./_dot_/g')"
printf ':Generated: %s\n' "on |date| by bzr2html_"
printf '\n.. _bzr2html: %s\n\n' 'http://wpr.cz/ccx/bzr/bzr2html/'
printf '%s\n\n' 'you can use ``bzr branch <this-url>`` to get this repository'
printf '* %s\n' '`commit log <./log.html>`_'
printf '* %s\n' '`files in this revision <./head.html>`_'
if [[ -f raw/README.rst ]]; then
	printf '\n.. include:: %s\n' raw/README.rst
elif [[ -f raw/README ]]; then
	printf '\n%s\n%s\n' README '======'
	printf '\n.. include:: %s\n' raw/README
	printf '   :%s:\n' literal
else
	printf '\n.. include:: %s\n' head.rst
fi