Adjust `makeover` to handle newer AsciiDoc output.
[gitmagic.git] / makeover
blobfa6a57f9700627ed4980d63c84ceeb4a1506e4a6
1 #!/usr/bin/env bash
3 # Extract table of contents from index.html and delete preface link.
4 BOOKDIR=book-$1
5 TITLE="Git Magic"
6 case $1 in
7 ru)
8 TITLE="Волшебство Git"
9 ;;
10 esac
12 # Older AsciiDoc versions put newlines in their output.
13 # To get them to work with the following, first minify the HTML output.
14 cat $BOOKDIR/index.html \
15 | grep -o '<div class="toc">.*' \
16 | sed 's!</div>.*!</div>!' \
17 | sed 's!<pr01.html\>!index.html!g' \
18 | sed 's!<li>!<li><b>'"$TITLE"'</b></li>&!' \
19 > toc.tmp
21 # For every file except the index...
22 for FILE in $BOOKDIR/*.html
24 sed '/<title>/a <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">' -i $FILE
25 if [ $FILE != "$BOOKDIR/index.html" ]
26 then
27 # Prepend "Git Magic - " to titles of all pages.
28 sed '/<title>/ s/<title>/&'"$TITLE"' - /' -i $FILE
29 sed 's/pr01\.html/index.html/g' -i $FILE
30 # Insert newline after `body` tag.
31 sed 's/<body[^>]*>/&\n/' -i $FILE
32 # Paste ToC into beginning and add div section with class content for CSS.
33 sed '/<body/{r toc.tmp
34 a <div class="content">
35 }' -i $FILE
36 sed 's!</body>!</div>&!' -i $FILE
38 done
40 # Originally this link was "My Homepage". Since it appears on translations of
41 # the guide, I changed it to my name so it doesn't have to be translated.
42 sed '/^<\/body/i </div><div class="footer"><a href="/~blynn/">Ben Lynn</a></div>' -i $BOOKDIR/*.html
44 cp $BOOKDIR/pr01.html $BOOKDIR/index.html
45 rm toc.tmp