2016.04.10
Ubuntu14.04.4
gitbook文档 GitBook Documentation
可以参考 Ubuntu14.04安装nodejs ,这里只用了编译源码的方法,还可以使用apt-get的方法下载软件包。
编译源码:
cd node-v4.4.2
./configure
make
sudo make install #这里一定要加sudo
成功执行后,nodejs、npm就被安装好了。
查看nodejs、npm版本号,确认安装无误
➜ ~: nodejs -v
v4.4.2
➜ ~: npm -v
2.15.0
npm install -g gitbook-cli
查看gitbook是否安装成功:
gitbook -V
➜ ~ sudo npm install -g gitbook-cli
/usr/local/bin/gitbook -> /usr/local/lib/node_modules/gitbook-cli/bin/gitbook.js
[email protected] /usr/local/lib/node_modules/gitbook-cli
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected]
└── [email protected] ([email protected], [email protected])➜ ~ gitbook -V
2.1.3
README.md 这个文件相当于一本Gitbook的简介。
touch README.mdSUMMARY.md 这个文件是一本书的目录结构,使用Markdown语法
touch SUMMARY.md
在SUMMARY.md 输入:
* [简介](README.md)
* [第一章](chapter1/README.md)
- [第一节](chapter1/section1.md)
- [第二节](chapter1/section2.md)
* [第二章](chapter2/README.md)
- [第一节](chapter2/section1.md)
- [第二节](chapter2/section2.md)
* [结束](end/README.md)
当这个目录文件创建好之后,我们可以使用Gitbook的命令行工具将这个目录结构生成相应的目录及文件:
输入命令 gitbook init
➜ gitbook init
info: init book at /home/michael/test1/book
info: detect structure from SUMMARY (if it exists)
info: found README.md
info: create chapter1/README.md
info: create chapter1/section1.md
info: create chapter1/section2.md
info: create chapter2/README.md
info: create chapter2/section1.md
info: create chapter2/section2.md
info: create end/README.md
info: initialization is finished
Done, without error
➜ book ls
chapter1 chapter2 end README.md SUMMARY.md
tree . #查看建立的目录和文件
.
├── chapter1
│ ├── README.md
│ ├── section1.md
│ └── section2.md
├── chapter2
│ ├── README.md
│ ├── section1.md
│ └── section2.md
├── end
│ └── README.md
├── README.md
└── SUMMARY.md
我们可以看到,gitbook给我们生成了与SUMMARY.md所对应的目录及文件。
每个目录中,都有一个README.md文件,相当于一章的说明。
gitbook serve .
➜ book gitbook serve .
Live reload server started on port: 35729
Press CTRL+C to quit ...
info: loading book configuration....OK
info: load plugin gitbook-plugin-highlight ....OK
info: load plugin gitbook-plugin-search ....OK
info: load plugin gitbook-plugin-sharing ....OK
info: load plugin gitbook-plugin-fontsettings ....OK
info: load plugin gitbook-plugin-livereload ....OK
info: >> 5 plugins loaded
info: start generation with website generator
info: clean website generatorOK
info: generation is finished
Starting server ...
Serving book on http://localhost:4000
然后浏览器中输入 http://localhost:4000 就可以预览生成的以网页形式组织的书籍。
gitbook build .
命令直接生成静态网站➜ book gitbook build .
info: loading book configuration....OK
info: load plugin gitbook-plugin-highlight ....OK
info: load plugin gitbook-plugin-search ....OK
info: load plugin gitbook-plugin-sharing ....OK
info: load plugin gitbook-plugin-fontsettings ....OK
info: >> 4 plugins loaded
info: start generation with website generator
info: clean website generatorOK
info: generation is finished
Done, without error
➜ book ls
_book chapter1 chapter2 end README.md SUMMARY.md
这里你会发现,你在你的图书项目的目录中多了一个名为_book的文件目录,而这个目录中的文件,即是生成的静态网站内容。
可以指定输出目录 gitbook build . /home/michael/book_output
输入为PDF文件,需要先使用NPM安装上gitbook-pdf:
$ sudo npm install gitbook-pdf -g
这个命令会出现错误,需要手动下载及编译phantomjs工具
git clone git://github.com/ariya/phantomjs.git
安装编译需要的工具和依赖
sudo apt-get install ruby bison flex gperf m4 python
sudo apt-get install libbison-dev libfl-dev libruby1.9.1 libyaml-0-2
sudo apt-get install libssl-dev libpng-dev libjpeg-dev
sudo apt-get install libicu-dev libx11-dev libxext-dev
sudo apt-get install libfontconfig1-dev libfreetype6 libsqlite3-dev
sudo apt-get install libasound2-dev
sudo apt-get install libwayland-dev
现在可以开始编译源码了:
cd phantomjs
git checkout 1.9.7 注意:这里的1.9.7是phantom的版本号,可以由错误报告的第一行找出
./build.sh –jobs 4 使用jobs时我会出现问题,添加以上最后两个库后,直接不用jobs编译成功
sudo cp bin/phantomjs /bin/
sudo npm install gitbook-pdf -g 重新进行安装
➜ ~ sudo npm install gitbook-pdf -g
npm WARN deprecated lodash@2.4.1: lodash@<3.0.0 is no longer maintained. Upgrade to lodash@^4.0.0.
npm WARN deprecated npmconf@0.0.24: this package has been reintegrated into npm and is now out of date with respect to npm
-
> phantomjs@1.9.7-5 install /usr/local/lib/node_modules/gitbook-pdf/node_modules/phantomjs
> node install.js
Writing location.js file
PhantomJS is already installed at /usr/bin/phantomjs.
/usr/local/bin/gitbook-pdf -> /usr/local/lib/node_modules/gitbook-pdf/bin/gitbook-pdf.js
gitbook-pdf@0.0.2 /usr/local/lib/node_modules/gitbook-pdf
├── commander@2.2.0
├── q@1.0.1
├── lodash@2.4.1
└── phantomjs@1.9.7-5 (which@1.0.9, kew@0.1.7, rimraf@2.2.8, ncp@0.4.2, adm-zip@0.2.1, mkdirp@0.3.5, npmconf@0.0.24)
最后,安装生成PDF依赖库:
$ sudo apt-get install calibre
使用命令gitbook pdf .
生成pdf文档,此时会出现更新步骤:
➜ test git:(master) gitbook pdf .
Installing GitBook 2.6.7
gitbook@2.6.7 ../../../../../../tmp/tmp-11408QlYw2Y5m0b5R/node_modules/gitbook
├── bash-color@0.0.3
├── escape-string-regexp@1.0.3
├── nunjucks-filter@1.0.0
├── gitbook-plugin-livereload@0.0.1
├── gitbook-plugin-sharing@1.0.1
├── github-slugid@1.0.0
├── gitbook-plugin-fontsettings@1.0.2
├── nunjucks-autoescape@1.0.0
├── jsonschema@1.0.2
├── spawn-cmd@0.0.2
├── q@1.0.1
├── json-schema-defaults@0.1.1
├── graceful-fs@3.0.5
├── semver@5.0.1
├── urijs@1.17.0
├── crc@3.2.1
├── tmp@0.0.24
├── npmi@0.1.1 (semver@4.3.6)
├── resolve@0.6.3
├── merge-defaults@0.2.1 (lodash@2.4.2)
├── dom-serializer@0.1.0 (domelementtype@1.1.3, entities@1.1.1)
├── send@0.2.0 (fresh@0.2.4, range-parser@1.0.3, mime@1.2.11, debug@2.2.0)
├── lodash@3.10.1
├── nunjucks@2.2.0 (asap@2.0.3, optimist@0.6.1)
├── i18n@0.5.0 (sprintf@0.1.5, mustache@2.2.1, debug@2.2.0)
├── fs-extra@0.16.5 (jsonfile@2.2.3, rimraf@2.5.2)
├── fstream-ignore@1.0.2 (inherits@2.0.1, minimatch@2.0.10, fstream@1.0.8)
├── gitbook-plugin-search@1.1.0 (lunr@0.5.12)
├── npm@2.4.1
├── gitbook-plugin-highlight@1.0.3 (highlight.js@8.8.0)
├── cheerio@0.19.0 (entities@1.1.1, css-select@1.0.0, htmlparser2@3.8.3)
├── request@2.51.0 (forever-agent@0.5.2, aws-sign2@0.5.0, caseless@0.8.0, tunnel-agent@0.4.2, oauth-sign@0.5.0, stringstream@0.0.5, json-stringify-safe@5.0.1, tough-cookie@2.2.2, mime-types@1.0.2, qs@2.3.3, node-uuid@1.4.7, combined-stream@0.0.7, http-signature@0.10.1, hawk@1.1.1, form-data@0.2.0, bl@0.9.5)
├── gitbook-parsers@0.8.9 (q@1.4.1, gitbook-restructuredtext@0.2.3, gitbook-markdown@0.5.3, gitbook-asciidoc@0.2.4)
├── chokidar@1.0.6 (path-is-absolute@1.0.0, arrify@1.0.1, is-glob@1.1.3, async-each@0.1.6, is-binary-path@1.0.1, glob-parent@1.3.0, readdirp@1.4.0, anymatch@1.3.0)
├── tiny-lr@0.2.1 (parseurl@1.3.1, livereload-js@2.2.2, qs@5.1.0, debug@2.2.0, faye-websocket@0.10.0, body-parser@1.14.2)
└── juice@1.5.0 (commander@2.3.0, slick@1.12.1, batch@0.5.2, cssom@0.3.0, web-resource-inliner@1.1.4)
info: loading book configuration....OK
info: load plugin gitbook-plugin-highlight ....OK
info: load plugin gitbook-plugin-search ....OK
info: load plugin gitbook-plugin-sharing ....OK
info: load plugin gitbook-plugin-fontsettings ....OK
info: >> 4 plugins loaded
info: start generation with pdf generator
info: clean pdf generatorOK
info: write SUMMARY.html
info: start conversion to pdf ....OK
info: generation is finished
info: >> 1 file(s) generated
Done, without error
➜ test git:(master) ls
book.pdf chapter1 chapter2 end README.md SUMMARY.md
可以看到在当前目录生成book.pdf
参考:
http://blog.csdn.net/xiaocainiaoshangxiao/article/details/46882921
http://www.linuxeden.com/html/softuse/20140409/150458.html
http://bluereader.org/article/159629980