設定流程
1. Personal access token
A. 申請 Personal access token
在右上角 Github 頭像 -> Settings -> Developer settings -> Personal access tokens -> Generate new token
勾選 repo:status
public_repo
注意: 要保存好剛產生出來 token
B. 將 Personal access token 寫入至 repositories 的 Secrets
在你的 repositories Settings -> Secrets -> New repository secre
將上一步驟的 token 寫入, 並命名 GH_ACCESS_TOKEN
2. 建立 GitHub Actions YAML
新增 GitHub Actions 的腳本在此路徑:.github/workflows/build.yml
此腳本功能是當你 push code 至 main branch 時, 會執行 jobs 的指令, 藉由 Gitbook CLI 將檔案 build 到 gh-pages
此 branch 的 _book 資料夾
需修改你想要的 branches, MYEMAIL
3. GitHub Pages 設定
在你的 repositories Settings->Pages
Source 的 Branch 選 gh-pages
4. 測試腳本
在你的 repositories Actions -> Workfows -> Run workflow
他就開始跑 yml 腳本, 可以點進去看他執行的 log
Gitbook 指令, 插件
如果要在本地端使用的話
install gitbook package
npm install -g gitbooknpm install -g gitbook-cli
fix: /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287 if (cb) cb.apply(this, arguments)
cd /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/npm install graceful-fs@4.2.0 --save
gitbook commands
generate SUMMARY.md
book sm -i _book node_modules
start service
gitbook serve .
build static file
gitbook build --output=/build/recipe
可以將想要的插件寫在 book.json
-:代表停用此plugin
{"plugins": [ "-search", "-lunr", "search-plus"]}
如果是本地端要測試的話, 需執行 gitbook install
可以參考這裡https://gitbookio.gitbooks.io/documentation/content/format/plugins.html
Reference
- https://wastemobile.gitbooks.io/gitbook-chinese/content/book/gitbook-cli.html
- https://github.com/wangzhebufangqi/auto-export-gitbook
- http://www.chengweiyang.cn/gitbook/github-pages/README.html
- https://www.cnblogs.com/snowdreams1006/p/12023904.html
- https://blog.csdn.net/qq_40889820/article/details/110013310