Added two chapters
[gitmagic/dustin.git] / makeover
blob4da83b9626dc7be03c459ec5b8b90c3994cd45be
1 #!/bin/bash
3 # extract table of contents from index.html
4 BOOKDIR=book
5 gawk '
6 /<div class="toc">/ {
7 print $0
8 getline #TODO: check this is the <ul> line
9 print $0
10 print "<li><a href=\".\">Git Magic</a></li>"
11 getline
12 while (!match($0, "</div>")) {
13 print $0
14 getline
16 print "</div>"
17 exit
19 ' < $BOOKDIR/index.html > toc.tmp
21 # for every chapter...
22 for FILE in $BOOKDIR/*.html
24 if [ $FILE != "$BOOKDIR/index.html" ]
25 then
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">
32 } ' -i $FILE
33 sed '/^<\/body/i </div>' -i $FILE
35 done
37 # extract shell of index.html
38 # then insert ToC and preface
39 gawk '
40 /<div class="book"/ {
41 i = 0
42 for(;;) {
43 getline
44 if (match($0, "<div")) i++;
45 else if (match($0, "</div")) {
46 i--;
47 if (i < 0) break;
50 sub("</div>","")
52 { print }
53 ' < $BOOKDIR/index.html | sed '/<body/{n; r toc.tmp
54 a <div class="content">
55 r preface.html
56 a </div>
57 } ' > tmp.tmp
58 mv tmp.tmp $BOOKDIR/index.html
59 rm toc.tmp