基本操作
安装
- GitBook 命令行工具:
npm install gitbook-cli -g
- 查看版本:
gitbook -V
创建一本书
初始化:
gitbook init
构建:
gitbook build
——在项目的目录下生成一个_book
目录,里面的内容为静态站点的资源文件启动服务
gitbook serve
——运行一个 web 服务, 通过http://localhost:4000/
可以预览书籍生成电子书:
# Generate a PDF file
$ gitbook pdf ./ ./mybook.pdf
# Generate an ePub file
$ gitbook epub ./ ./mybook.epub
# Generate a Mobi file
$ gitbook mobi ./ ./mybook.mobi
Gitbook配置和插件
其他 Q&A
How to remove “Published with Gitbook”
-
please create
styles/website.css
文件链接.gitbook-link { display: none !important; }
then, edit
book.json
文件链接{ "styles": { "website": "styles/website.css" } }
gitbook build 生成的HTML无法跳转问题
-
使用如下命令
gitbook build --gitbook=2.6.7
如果遇到:
Error loading version latest: Error: Cannot find module 'internal/util/types'
安装node管理 n
sudo npm install -g n
降低版本,更新npm
sudo n 6
安装npm
sudo npm install npm -g
此时运行gitbook2.6.7的命令即可。
gitbook build --gitbook=2.6.7
待转换完成后,将npm版本(例如11.11.1)切回来即可,以免影响其他模块
sudo n 11.11.1