安装
npm install gitbook-cli -g
初始化
在需要写文档的文件夹下执行
gitbook init
等待初始化完成后会有两个文件
README.md #首页SUMMARY.md #左侧菜单
启动
gitbook serve
指定端口号
gitbook serve --port 2333
菜单编写
SUMMARY.md基本格式如下
# 目录* [前言](README.md)* [第一章](Chapter1/README.md) * [第1节:first](Chapter1/first.md) * [第2节:second](Chapter1/senond.md) * [第3节:third](Chapter1/third.md) * [第4节:fourth](Chapter1/fourth.md)* [第二章](Chapter2/README.md)* [第三章](Chapter3/README.md)* [第四章](Chapter4/README.md)
文档导出
gitbook build [文档路径] [输出路径]
pdf格式
gitbook pdf ./ ./mybook.pdf
如果遇到以下提示
InstallRequiredError: "ebook-convert" is not installed.Install it from Calibre: https://calibre-ebook.com
表示缺少ebook-convert
插件
安装插件
首先需要配置一下gitbook,配置文件是当前文档目录下的book.json,类似于npm的package.json文件
新建book.json,需要的插件在plugins字段里,内容基本如下:
{ "title" : "我的文档", "theme-default": { "showLevel": true }, "plugins": ["copy-code-button"]}
以copy-code-button
(代码复制按钮)插件为例
然后执行
gitbook install
更多插件介绍点击这里
更多详情参考官方文档