#!/bin/bash
# Extract table of contents from index.html and delete preface link.
BOOKDIR=book-$1
TITLE="Git Magic"
case $1 in
ru)
TITLE=" Git"
;;
esac
gawk '
// {
print $0
getline
print $0
print "
'"$TITLE"'"
getline
while (!match($0, "")) {
gsub("pr01.html", "index.html")
print $0
getline
}
print $0
exit
}
' < $BOOKDIR/index.html > toc.tmp
# For every file except the index...
for FILE in $BOOKDIR/*.html
do
sed '//a ' -i $FILE
if [ $FILE != "$BOOKDIR/index.html" ]
then
# Prepend "Git Magic - " to titles of all pages.
sed '// s//&'"$TITLE"' - /' -i $FILE
sed 's/pr01\.html/index.html/g' -i $FILE
# Paste ToC into beginning and add div section with class content for CSS.
sed '/