Moved Google Analytics code to makeover script
[gitmagic.git] / makeover
blob47405cddd7f7aeea6b7d74bc348102696aaaecba
1 #!/bin/bash
3 # extract table of contents from index.html
4 # and delete preface link
5 BOOKDIR=book
6 gawk '
7 /<div class="toc">/ {
8 print $0
9 getline #TODO: check this is the <ul> line
10 print $0
11 print "<li><a href=\".\">Git Magic</a></li>"
12 getline
13 while (!match($0, "</div>")) {
14 if (match($0, "<li><span class=\"preface\"")) {
15 while (!match($0, "</span>")) {
16 getline
18 getline
20 print $0
21 getline
23 print "</div>"
24 exit
26 ' < $BOOKDIR/index.html > toc.tmp
28 # for every file except the index...
29 for FILE in $BOOKDIR/*.html
31 if [ $FILE != "$BOOKDIR/index.html" ]
32 then
33 # add "Git Magic - " to titles of all pages
34 sed '/<title>/ s/<title>/&Git Magic - /' -i $FILE
35 sed 's/pr01\.html/index.html/g' -i $FILE
36 # paste ToC into beginning
37 # and add div section with class content for CSS
38 sed '/<body/{n; r toc.tmp
39 a <div class="content">
40 } ' -i $FILE
41 sed '/^<\/body/i </div>' -i $FILE
43 done
45 sed '/^<\/body/i </div><div class="footer"><a href="/~blynn/">My Homepage</a></div>' -i $BOOKDIR/*.html
47 sed '/<\/body>/ i \
48 <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> \
49 </script> \
50 <script type="text/javascript"> \
51 _uacct = "UA-1901330-2"; \
52 urchinTracker(); \
53 </script>' -i $BOOKDIR/*.html
55 mv $BOOKDIR/pr01.html $BOOKDIR/index.html
56 rm toc.tmp