基础命令
这里主要介绍一下 GitBook 的命令行工具 gitbook-cli 的一些命令, 首先说明两点:
- gitbook-cli 和 gitbook 是两个软件
- gitbook-cli 会将下载的 gitbook 的不同版本放到 ~/.gitbook中, 可以通过设置GITBOOK_DIR环境变量来指定另外的文件夹
列出gitbook所有的命令:
初始化 gitbook:
gitbook init
该命令主要用户初始化 book,创建必要的 README 和 SUMMARY 文件
输出gitbook的帮助信息:
gitbook help
D:\gitbook>gitbook help
build [book] [output] build a book
--log Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
--format Format to build to (Default is website; Values are website, json, ebook)
--[no-]timing Print timing debug information (Default is false)
serve [book] [output] serve the book as a website for testing
输出gitbook-cli的帮助信息:
gitbook --help
D:\gitbook>gitbook --help
Usage: gitbook [options] [command]
Options:
-v, --gitbook [version] specify GitBook version to use
-d, --debug enable verbose error
-V, --version Display running versions of gitbook and gitbook-cli
-h, --help output usage information
Commands:
ls List versions installed locally
current Display currently activated version
ls-remote List remote versions available for install
fetch [version] Download and install a <version>
alias [folder] [version] Set an alias named <version> pointing to <folder>
uninstall [version] Uninstall a version
update [tag] Update to the latest version of GitBook
help List commands for GitBook
* run a command with a specific gitbook version
下载所需的资源,如插件等:
gitbook install
D:\gitbook\book2-theme-default>gitbook install
info: installing 3 plugins using npm@3.9.2
info:
info: installing plugin "splitter"
info: install plugin "splitter" (*) from NPM with version 0.0.8
D:\gitbook\book2-theme-default
`-- gitbook-plugin-splitter@0.0.8
info: >> plugin "splitter" installed with success
...
如果插件比较多,下载会花很长时间。
可以用 npm install plugin-xxx
这种方式单个下载插件。
生成静态网页:
gitbook build
D:\temp>gitbook build
info: 7 plugins are installed
info: 6 explicitly listed
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 2 pages
info: found 4 asset files
info: >> generation finished with success in 0.4s !
运行完该命令后,会在当前文件夹中生成一个 _book
文件夹,其中就是解析出来的静态网站,包含了点子书中的所有信息。
可以将它直接放置在如 nginx 、apache server 、tomcat等服务器中直接运行。
用浏览器直接打开生成的 html 文件是可以的,但是无法完成基本的交互。
生成静态网页并运行服务器:
gitbook serve
D:\temp>gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...
info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 2 pages
info: found 4 asset files
info: >> generation finished with success in 0.5s !
Starting server ...
Serving book on http://localhost:4000
用浏览器直接访问 http://localhost:4000/,就可以看到生成的电子书网站。
生成时指定gitbook的版本, 本地没有会先下载:
gitbook build --gitbook=2.0.1
列出本地所有的gitbook版本:
gitbook ls
D:\temp>gitbook ls
GitBook Versions Installed:
* 3.2.3
Run "gitbook update" to update to the latest version.
列出远程可用的gitbook版本:
gitbook ls-remote
D:\temp>gitbook -V
CLI version: 2.3.2
GitBook version: 3.2.3
gitbook --version
可以得到同样的结果。
C:\Users\admin>gitbook --version
CLI version: 2.3.2
GitBook version: 3.2.3
安装对应的gitbook版本:
gitbook fetch 标签/版本号
更新到gitbook的最新版本:
gitbook update
卸载对应的gitbook版本:
gitbook uninstall 2.0.1
指定log的级别:
gitbook build --log=debug
输出错误信息:
gitbook build --debug
D:\temp\>gitbook build --debug
info: 23 plugins are installed
info: 9 explicitly listed
info: loading plugin "splitter"... OK
info: loading plugin "anchor-navigation-ex"... OK
info: loading plugin "versions-select"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 28 pages
info: found 68 asset files
info: >> generation finished with success in 4.6s !
- 生成其他格式的文件命令在 扩展章节