http://blog.cugxuan.cn/2018/12/03/Markdown/How-to-use-gitbook-elegantly/
先扯幾句有的沒的竹观,Gitbook
是很好的工具臭增,雖然官網(wǎng)現(xiàn)在貌似把他升級到 Gitbook/V2
的版本了竹习,也沒有說明一堆用法(我還不懂咋玩),所以現(xiàn)在用的都是舊版本的 Gitbook
整陌,網(wǎng)址自然就是 https://legacy.gitbook.com/
這兒推薦一個團隊協(xié)同編輯的規(guī)范 中文文案排版指北(簡體中文版)泌辫。
本文的目的是推薦幾個比較好用的插件以及聊聊我的 Gitbook 使用方法
介紹
GitBook 是一個基于 Node.js 的命令行工具,可使用 Github/Git 和 Markdown 來制作精美的電子書宾毒,GitBook 并非關(guān)于 Git 的教程澜搅。 –摘自《百度百科》
入門
入門這種東西我就不往這兒貼了勉躺,因為太多了。別人的教程寫的更好饵溅,比較推薦大家去讀一讀 Gitbook 使用教程
插件推薦
在根目錄的 book.json
下編輯即可,可以使用 gitbook install ./
來自動安裝設置的插件
mathjax
地址: https://plugins.gitbook.com/plugin/mathjax
- 可以在 Markdown 中輸入 Latex 公式
- 可以在網(wǎng)頁上右鍵非常方便得顯示出 MathML 格式的代碼和 LaTeX 格式的代碼冠句。
splitter
地址: https://plugins.gitbook.com/plugin/splitter
提供了一個可以拖動的分割正文和目錄的垂直條幸乒。
github-buttons
地址: https://plugins.gitbook.com/plugin/github-buttons
提供了一個非官方的github的star和fork等的顯示,具體用法可以看文檔
copy-code-button
地址: https://plugins.gitbook.com/plugin/copy-code-button
在代碼段中添加一個copy按鈕
search-plus
地址: https://plugins.gitbook.com/plugin/search-plus
更強大的一個搜索工具
anchor-navigation-ex-toc
地址: https://plugins.gitbook.com/plugin/anchor-navigation-ex-toc
為文章增加錨點目錄欄以及回到頂部等功能
- 在頁面中增加標簽聚唐,會在此處生成TOC目錄
- 在頁面中增加標簽杆查,不會在該頁面生成懸浮導航
donate
地址: https://plugins.gitbook.com/plugin/donate
打賞插件,具體功能看文檔
book.json
放一個自用的 book.json
{
"title" : "Gitbook Use",
"author" : "Xuan",
"language" : "zh-hans",
"links" : {
"sidebar" : {
"Home" : "http://notes.cugxuan.cn"
}
},
"plugins": [
"mathjax",
"splitter",
"github-buttons",
"copy-code-button",
"-lunr",
"-search",
"search-plus",
"expandable-chapters-small",
"anchor-navigation-ex"
],
}
如何部署
這里選擇的是使用 github
進行部署亲桦,為此我寫了一個腳本 deploy.sh
在 remote_url 中輸入自己項目的地址客峭,在 master 分支放自己的內(nèi)容即可桃笙。
#!/bin/bash
# 設置遠程倉庫的地址
remote_url=git@github.com:PointStoneTeam/PointStone388.git
# 獲取當前時間
cur_date="`date +%Y-%m-%d-%H:%M:%S`"
# 生成_book文件
gitbook build
rm -rf .deploy_git/* | egrep .deploy_git/.git
if [ ! -d ".deploy_git/" ];then
cp -R _book/ .deploy_git/
else
cp -R _book/* .deploy_git/
fi
cd .deploy_git/
git init
git remote add origin $remote_url
git checkout -b gh-pages
git add -A
git commit -m $cur_date
git push -f origin gh-pages
|
如何使用 Deploy 腳本
需要環(huán)境
- 安裝
nodejs
環(huán)境 - 安裝
npm install gitbook-cli -g
- 執(zhí)行
gitbook install ./
- 執(zhí)行
gitbook serve
- 擁有倉庫的推送權(quán)限
使用部署
- 將源文件更新到項目的
master
分支
$ git add -A
$ git commit -m "xx"
$ git push origin master
- 進行部署
$ ./deploy.sh
//如果沒有權(quán)限沙绝,先給腳本以執(zhí)行權(quán)限
$ chmod a+x deploy.sh
效果
在執(zhí)行了 ./deploy.sh
之后闪檬,會自動在 github
的 gh-pages
分支上更新。
然后可以直接瀏覽網(wǎng)站查看效果 https://pointstoneteam.github.io/PointStone388/