GitBook 安装使用,及遇到的坑【Mac下】

1、安装gitbook命令行
[code]
$ npm install -g gitbook-cli
[/code]
2、查看是否安装成功
[code]
$ gitbook -V
[/code]
3、开始使用
(1)初始化
[code]
$ mkdir test_gitbook
$ cd test_gitbook
$ touch README.md
$ touch SUMMARY.md
$ vi 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)
[/code]
(2)生成目录结构
[code]
$ gitbook init
[/code]
(3)查看目录结构
[code]
$ tree
.
├── README.md
├── SUMMARY.md
├── chapter1
│   ├── README.md
│   ├── section1.md
│   └── section2.md
├── chapter2
│   ├── README.md
│   ├── section1.md
│   └── section2.md
└── end
└── README.md
[/code]
(4)本地预览
[code]
$ gitbook serve .
[/code]

这一步可能会报错
[code]
(node:12474) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
(node) v8::ObjectTemplate::Set() with non-primitive values is deprecated
(node) and will stop working in the next major release.
[/code]

查看node版本
[code]
$ node -v
v6.0.0
[/code]

原因是:graceful-fs 在 node V6 下不支持,需要降级
[code]
$ brew tap homebrew/versions
$ brew unlink node
$ brew install homebrew/versions/node5
$ node -v
v5.11.1
[/code]

PS:如果需要使用node 6.0
[code]
brew unlink homebrew/versions/node5
brew link node
[/code]
切回5.11
[code]
brew unlink node
brew link homebrew/versions/node5
[/code]

好了,继续执行
[code]
$ 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
[/code]

浏览器打开 http://localhost:4000
可以看到效果啦

这时可以看到当前目录下多了个文件夹
_book
这个文件里面是静态网站内容

生成静态网站到指定目录
[code]
gitbook build . ./mysite
[/code]

(5)gitbook 常用命令
[code]
$ gitbook -h
Usage: gitbook [options] [command]
Commands:
build [options] [source_dir] 编译指定目录,输出Web格式(_book文件夹中)
serve [options] [source_dir] 监听文件变化并编译指定目录,同时会创建一个服务器用于预览Web
pdf [options] [source_dir] 编译指定目录,输出PDF
epub [options] [source_dir] 编译指定目录,输出epub
mobi [options] [source_dir] 编译指定目录,输出mobi
init [source_dir] 通过SUMMARY.md生成作品目录
Options:
-h, --help output usage information
-V, --version output the version number
[/code]
(6)gitbook 生成pdf
[code]
$ gitbook pdf . mypdf.pdf
Error: Need to install ebook-convert from Calibre
[/code]
这时候去下载Calibre
http://calibre-ebook.com/download_osx
安装完成后
[code]
ln -s /Applications/calibre.app/Contents/MacOS/ebook-convert /usr/local/bin
[/code]
再次执行
[code]
$ gitbook pdf . mypdf.pdf
[/code]
会在当前目录下生成 mypdf.pdf
(7)使用 gitbook editor 制作电子书
下载地址:https://www.gitbook.com/editor/

这个就不再赘述了。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值