-
Notifications
You must be signed in to change notification settings - Fork 1
/
title_update.sh
103 lines (78 loc) · 2.19 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
99
100
101
102
103
#!/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}/docker-docs.git"
#rm -rf About.md
book sm
#sed -i 's/Gitbook Demo/目录/g' About.md
python3 gitbook-auto-summary.py .
delete_README() {
lines_README=`cat SUMMARY-GitBook-auto-summary.md | grep "*" |grep README |grep -v "序言" | awk -F '(' '{print $2}' | awk -F ')' '{print $1}'`
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//\-/\\\-}
echo $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_sm=`echo $dir | sed 's/-/ /g'`
dir_README=`grep -E "\[${dir_sm}\]" 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
cp SUMMARY.md Overview.md
sed -r -i 's/summary/目录/g' SUMMARY.md
#sed -r -i '/序言/a\* \[目录\]\(.\/Overview\.md\)' SUMMARY.md
}
push_main(){
gitbook build
git add .
git commit -m "${update}"
git push origin main
}
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 main
git push --force --quiet "https://${TOKEN}@${repo}" main:gh-pages
}
delete_README
add_README
push_main
push_gh-pages
exit 0