-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtitle_update.sh
98 lines (74 loc) · 2 KB
/
title_update.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
#!/bin/bash
# author: ghostwritten
# date: 01/06 2022
# description: deploy Github Pages
# ##############################################################################
set -o nounset
FILE_NAME="deploy"
FILE_VERSION="v1.0"
BASE_DIR="$( dirname "$( readlink -f "${0}" )" )"
if [ $# != 1 ] ; then
echo "USAGE: $0 something "
echo " e.g.: $0 update github pages"
exit 1;
fi
update=$1
#token=$2
user='Ghostwritten'
email='[email protected]'
repo="github.com/${user}/gitbook-docs.git"
rm -rf About.md
book sm
cp SUMMARY.md Overview.md
sed -i 's/Gitbook Demo/目录/g' Overview.md
python3 gitbook-auto-summary.py .
delete_README() {
lines_README=`cat SUMMARY-GitBook-auto-summary.md |grep "*" |grep README |grep -v "序言" | awk '{print $2}'`
for line_README in $lines_README
do
echo $line_README
line_README=${line_README//\//\\\/}
line_README=${line_README//\[/\\[}
line_README=${line_README//\]/\\]}
line_README=${line_README//\(/\\\(}
line_README=${line_README//\)/\\\)}
line_README=${line_README//\-/\\\-}
sed -r -i "/$line_README/d" SUMMARY-GitBook-auto-summary.md
done
}
add_README() {
dirs=`grep -E '\- ' SUMMARY-GitBook-auto-summary.md | awk '{print $2}'`
for dir in $dirs
do
dir_README=`grep -E "\[${dir}\]" SUMMARY.md | sed 's/^[ \t]*//g'`
dir_README=${dir_README//\//\\\/}
dir_README=${dir_README//\[/\\[}
dir_README=${dir_README//\]/\\]}
dir_README=${dir_README//\(/\\\(}
dir_README=${dir_README//\)/\\\)}
dir_README=${dir_README//\-/\\\-}
sed -r -i "s#\\- ${dir}\$#$dir_README#g" SUMMARY-GitBook-auto-summary.md
done
mv SUMMARY-GitBook-auto-summary.md SUMMARY.md
}
push_master(){
gitbook build
git add .
git commit -m "${update}"
git push -f origin master
}
push_gh-pages(){
cp Overview.md _book/README.md
cd _book
git init
git remote add origin https://${repo}
git add .
git commit -m "${update} For Github Pages"
git branch -M master
git push --force --quiet "https://${TOKEN}@${repo}" master:gh-pages
}
delete_README
add_README
push_master
push_gh-pages
exit 0