Gitbook的默认模板是theme-default,可以把它fork一份,然后自由修改,并且可以直接引用github上repo作为插件。
将theme-defaultfork为theme-lijiaocn,可以在里面增加或删除一些字符,便于与theme-default区分开。
package.json
中的名称一定要修改:
将:
"name": "gitbook-plugin-theme-default",
"description": "Default theme for GitBook",
修改为:
"name": "gitbook-plugin-theme-lijiaocn",
"description": "Default theme for GitBook",
文件中的连接也修改:
1,$ s#https://github.com/GitbookIO/#https://github.com/lijiaocn/#
先安装gitbook-cli:
npm install gitbook-cli -g
gitbook命令默认位于/usr/local/bin中,需要将这个目录添加到环境变量PATH中:
export PATH="/usr/local/bin/":$PATH
创建一个gitbook项目:
mkdir custom-theme-example
cd custom-theme-example
gitbook init
如果遇到dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib的问题,可以用下面方法解决:
问题现象:
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib
Referenced from: /usr/local/bin//node
Reason: image not found
[1] 55441 abort gitbook init
解决方法:
brew update node
brew cleanup
在gitbook目录中创建项目的配置文件book.json。
{
"author": "[email protected]",
"isbn": "",
"language":"zh",
"gitbook": ">=3.0.0",
"plugins":""
}
采用How to use a custom theme hosted on Github?中的建议,将github上theme repo作为插件安装:
{
"author": "[email protected]",
"isbn": "",
"language":"zh",
"gitbook": ">=3.0.0",
"plugins":[
{
"name": "theme-lijiaocn",
"version": "git+https://github.com/lijiaocn/theme-lijiaocn.git"
}
]
}
运行gitbook install
安装:
$ gitbook install
info: installing 1 plugins using [email protected]
info:
info: installing plugin "theme-lijiaocn"
info: install plugin "theme-lijiaocn" (git+https://github.com/lijiaocn/theme-lijiaocn.git) from NPM with version git+https://github.com/lijiaocn/theme-lijiaocn.git
/Users/lijiao/Work-Finup/books/custom-theme-example
└── [email protected] (git+https://github.com/lijiaocn/theme-lijiaocn.git#3be9e673448b4a8e13e6405cb061cf4e172f2377)
启动:
gitbook serve --port 4005 --lrport 35735
theme-lijiaocn插件更新之后,在使用该插件的gitbook项目中直接重新安装一遍插件,就会应用最新的版本:
gitbook install
{
"plugins": ["sitemap"],
"pluginsConfig": {
"sitemap": {
"hostname": "http://mybook.com/"
}
}
}