-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish.sh
executable file
·108 lines (92 loc) · 2.12 KB
/
publish.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
# publish documentation to github pages (gh-pages branch)
ITEMS="""
html
singlehtml
latexpdf
epub
"""
DATE=`date '+%Y-%m-%d %H:%M:%S'`
publish_html() {
cp -r _build/html html
}
publish_singlehtml() {
cp -r _build/singlehtml singlehtml
}
publish_latexpdf() {
mkdir -p latexpdf
cp -r _build/latex/QWinFF.pdf latexpdf/qwinff.pdf
generate_redirect_page qwinff.pdf > latexpdf/index.html
}
publish_epub() {
mkdir -p epub
cp -r _build/epub/QWinFF.epub epub/qwinff.epub
generate_redirect_page qwinff.epub > epub/index.html
}
# usage: generate_redirect_page <target>
generate_redirect_page() {
echo """<html>
<head><meta http-equiv='refresh' content='0; url=$1'/></head>
<body>
<a href='$1'>$1</a>
</body>
</html>"""
}
generate_index() {
echo "<html><head><title>QWinFF User Documentation</title></head><body>"
echo "<h3>QWinFF User Documentation</h3>"
echo "<p>The following formats are available:</p>"
echo "<ul>"
for item in $ITEMS; do
echo "<li><a href=\"$item/index.html\">$item</a></li>"
done
echo "</ul>"
echo "<small>Last updated: $DATE</small>"
echo "</body></html>"
}
init_gh_pages_branch() {
git checkout --orphan gh-pages
}
UPDATED_ITEMS="\t"
# build pages
git checkout master || exit 1
make clean
for item in $ITEMS; do
echo building $item
make $item > /dev/null
[ $? -ne 0 ] && exit 1
done
# commit pages to gh-pages branch
git checkout gh-pages || init_gh_pages_branch
if [ $? -ne 0 ]; then
echo "failed to switch to gh-pages"
exit 1
fi
git rm -rf . >& /dev/null
for item in $ITEMS; do
publish_$item && git add $item >& /dev/null
if [ $? -eq 0 ]; then
echo "successfully updated $item"
UPDATED_ITEMS="${UPDATED_ITEMS}${item}\n\t"
else
echo "ERROR: failed to update $item"
git checkout HEAD .
git checkout master
exit 1
fi
done
LOG="Update on $DATE.\n\nupdated items:\n$UPDATED_ITEMS"
LOG=`echo -e "$LOG"`
generate_index > index.html && git add index.html
touch .nojekyll
git add .nojekyll
git commit -m "$LOG"
# push to remote
read -p "push to remote? [y/N]: " reply
if [ "$reply" != "y" ]; then
echo "not pushing to remote"
else
echo "pushing to remote"
git push --force
fi
git checkout master