Rephrased a few sentences
[gitmagic.git] / makeover
blob4e0faa1356696d312ac9a40de5ccecf9b6387dc3
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 sed '/^<\/body/i </div><div class="footer"><a href="/~blynn/">My Homepage</a></div>' -i $BOOKDIR/*.html
39 # extract shell of index.html
40 # then insert ToC and preface
41 gawk '
42 /<div class="book"/ {
43 i = 0
44 for(;;) {
45 getline
46 if (match($0, "<div")) i++;
47 else if (match($0, "</div")) {
48 i--;
49 if (i < 0) break;
52 sub("</div>","")
54 { print }
55 ' < $BOOKDIR/index.html | sed '/<body/{n; r toc.tmp
56 a <div class="content">
57 r preface.html
58 a </div>
59 } ' > tmp.tmp
60 mv tmp.tmp $BOOKDIR/index.html
61 rm toc.tmp