初始化一本書,名字叫 mybook(若是不寫名字,默認生成_book的書名)git
命令格式:gitbook init 書名github
gitbook init mybooknpm
使用命令gitbook init,則生成一系列目錄文件,見下方;瀏覽器
[lsug@minion mybook]$ tree .
.
├── book
│ ├── editor.md
│ ├── gitbook-cli.md
│ └── README.md
├── end
│ └── README.md
├── howtouse
│ ├── gitbookcli.md
│ ├── gitbookinstall.md
│ ├── Nodejsinstall.md
│ └── README.md
├── output
│ ├── outfile.md
│ ├── pdfandebook.md
│ └── README.md
├── publish
│ ├── gitbook.md
│ ├── github.md
│ ├── gitpages.md
│ └── README.md
├── README.md
└── SUMMARY.mdmarkdown
5 directories, 17 filesfetch
每一個目錄中,都有一個README.md
文件,至關於一章的說明。網站
使用Gitbook的命令行進行本地預覽ui
命令格式:gitbook serve ./圖書名稱spa
[lsug@minion devops]$ gitbook serve ./mybook
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 1 pages
info: found 0 asset files
info: >> generation finished with success in 1.6s !
Starting server ...
Serving book on http://localhost:4000
而後瀏覽器中輸入 http://localhost:4000 或者http://172.16.1.81:4000就能夠預覽生成的以網頁形式組織的書籍。
執行gitbook build 命令會生成靜態網站
命令格式:gitbook build 圖書目錄 輸出目錄
[lsug@minion devops]$ 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 1 pages
info: found 0 asset files
info: >> generation finished with success in 1.1s !
這裏你會發現,你在你的圖書項目的目錄中多了一個名爲_book的文件目錄,而這個目錄中的文件,便是生成的靜態網站內容。
3-輸出PDF
輸出爲PDF文件,須要先使用NPM安裝上gitbook-pdf:
sudo npm install gitbook-pdf -g (安裝會報錯,phantomjs包沒有安裝)
進入目錄,生成pdf文檔
cd /data/gitbook/devops
gitbook pdf .
解決報錯
export PHANTOMJS_CDNURL=http://cnpmjs.org/downloads npm install phantomjs
npm install -g phantomjs
查看幫助
[root@minion gitbook]# gitbook --help
Usage: gitbook [options] [command]
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
Options:
-h, --help output usage information
-v, --gitbook [version] specify GitBook version to use
-d, --debug enable verbose error
-V, --version Display running versions of gitbook and gitbook-cli
書籍編輯:
gitbook書籍編輯有兩種方法:
a-gitbook命令行
b-markdown編輯
README.md和SUMMARY.md是Gitbook項目必備的兩個文件;
README.md:這個文件至關於一本Gitbook的簡介,最上層(和SUMMARY.md同級)的是本書的Introduction
SUMMARY.md:這個文件是一本書的目錄結構,使用Markdown語法, 這個文件在使用gitbook命令行以前要先寫好,以便以後生成書籍目錄