写一个脚本自动发布你的GitBook

写一个脚本自动发布你的GitBook

GitBookBuild以后,会产生一个_book的目录,里面存放着整个html
目录.只要将这个目录发布到你的Page中,就可以实现GitPage了.

前提

  • 先创建一个空的GitRepo.
  • Repo中创建两个Branch, 一个为书写Branch,在本例中为write,另一个为发布branch,在本例中为master.
  • 将下面的脚本加入书写branch中.

脚本

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
# 先保存当前的Repo状态
git add .
git commit -a -m "Update master"
git push origin write

# 构建GitBook
gitbook install && gitbook build

# 切换到发布版本
git checkout master

# 拉取GitBook发布版本的最新版
git pull origin master --rebase

# 将_book内容移到根目录
cp -R _book/* .

# 删除 'node_modules' 和 '_book' 目录
git clean -fx node_modules
git clean -fx _book

# 将所有的文件添加到Repo中
git add .

# 提交
git commit -a -m "Update docs"

# 发布到Master
git push origin master

# 切换回书写版本
git checkout write

因为我的GitPage是发布在Coding上的,Coding不支持将除master分支之外的分支发布到page上,所以上面的脚本中,
书写分支为write,发布分支为master.

注:

有两个.gitignore文件需要注意一下:

分支write中,不需要html文件:

1
2
3
node_modules/
*.html
_book/

分支master中不需要发布脚本和md源文件:

1
2
3
node_modules/
*.md
publish.sh

写一个脚本自动发布你的GitBook

https://www.borgor.cn/posts/dbe45b51.html

作者

Cyrusky

发布于

2019-12-02

更新于

2024-11-18

许可协议

评论