持续更新 github pages


文章目录



1. 新增 md

$ ls
_book gitbook index.html README.md search_index.json SUMMARY.md
$ ls _book/
gitbook index.html search_index.json

新增Gihub目录,以及文章
$ ls
_book gitbook Github index.html README.md search_index.json SUMMARY.md

$ ls Github/
1_github_introduce.md 2_github_local_pull_github.md 3_github_action.md 4_github_page.md

2. 定制 book.json

或许偶尔你会手动更新book.json,比如:新增插件、分享链接等等。

$ cat book.json 
{
"author": "zongxun <me@ghostwritten>",
"description": "This is a sample book created by gitbook",
"extension": null,
"generator": "site",
"links": {
"sharing": {
"all": null,
"facebook": null,
"google": null,
"twitter": null,
"weibo": null
},
"sidebar": {
"zongxun's Blog": "https://smoothies.com.cn"
}
},
"output": null,
"pdf": {
"fontSize": 12,
"footerTemplate": null,
"headerTemplate": null,
"margin": {
"bottom": 36,
"left": 62,
"right": 62,
"top": 36
},
"pageNumbers": false,
"paperSize": "a4"
},
"plugins": [],
"title": "Git Handbook",
"variables": {}
}

$ ls
_book book.json gitbook Github index.html README.md search_index.json SUMMARY.md

更多细节请参考​​pages定制​

3. 脚本发布

新建 ​​Person Access Token​​​gitbook 更新 github pages_json
复制token

$ vim /etc/profile
export TOKEN=<xxxxxxxxxtokenxxxxxxxxxx>

修改个人配置信息

  • user=‘​​Ghostwritten​​’
  • email=‘​​1zoxun1@gmail.com​​’
  • repo=“​​github.com/${user}/gitbook-demo.git​​”
$ cat deploy.sh 
#!/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='1zoxun1@gmail.com'
repo="github.com/${user}/gitbook-demo.git"


python3 gitbook-auto-summary.py -o .

gitbook build

git add .
git commit -m "${update}"
git push origin master

cd _book
git init
git remote add origin https://${repo}
git add .
git commit -m "Update $user@repo For Github Pages"
git branch -M master
git push --force --quiet "https://${TOKEN}@${repo}" master:gh-pages

执行:

$ bash deploy.sh "update <something>"