gitbook入门

2次阅读

共计 835 个字符,预计需要花费 3 分钟才能阅读完成。

安装

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

更多插件介绍点击这里

更多详情参考官方文档

正文完
 0