3 # extract table of contents from index.html
8 getline #TODO: check this is the <ul> line
10 print "<li><a href=\".\">Git Magic</a></li>"
12 while (!match($0, "</div>")) {
19 ' < $BOOKDIR/index.html
> toc.tmp
21 # for every chapter...
22 for FILE
in $BOOKDIR/*.html
24 if [ $FILE != "$BOOKDIR/index.html" ]
26 # add " - Git Magic" to titles of all pages
27 sed '/<\/title>/ s/<\/title>/ - Git Magic&/' -i $FILE
28 # paste ToC into beginning
29 # and add div section with class content for CSS
30 sed '/<body/{n; r toc.tmp
31 a <div class="content">
33 sed '/^<\/body/i </div>' -i $FILE
37 # extract shell of index.html
38 # then insert ToC and preface
44 if (match($0, "<div")) i++;
45 else if (match($0, "</div")) {
53 ' < $BOOKDIR/index.html |
sed '/<body/{n; r toc.tmp
54 a <div class="content">
58 mv tmp.tmp
$BOOKDIR/index.html