GitBook快速入门

1.安装 Node.js

#Node 官网已经把 linux 下载版本更改为已编译好的版本了,我们可以直接下载解压后使用:
wget https://nodejs.org/dist/v10.15.3/node-v10.15.3-linux-x64.tar.xz
tar xf  node-v10.15.3-linux-x64.tar.xz  
cd node-v10.15.3-linux-x64/
./bin/node -v
#解压文件的 bin 目录底下包含了 node、npm 等命令,我们可以使用 ln 命令来设置软连接:
ln -s /data/server/node-v10.15.3-linux-x64/bin/npm   /usr/local/bin/
ln -s /data/server/node-v10.15.3-linux-x64/bin/node   /usr/local/bin/

2.修改npm镜像源

#修改npm的registry为淘宝镜像:
npm config set registry=http://registry.npm.taobao.org
#配置后可通过下面方式验证是否成功:
npm config get registry

3.安装GitBook

#使用命令行安装GitBook本地服务:
npm install gitbook-cli -g
#设置gitbook软连接:
ln -s /data/server/node-v10.15.3-linux-x64/bin/gitbook   /usr/local/bin/

4.使用GitBook
4.1.初始化
指定书籍目录并初始化:

gitbook init mybook


以当前目录为书籍目录并初始化:

gitbook init


4.2.构建

cd mybook
#生成_book目录和静态网页并运行服务:
gitbook build .
#也可以使用指定版本的方式:
gitbook build . --gitbook=3.2.0

5.启动服务

#生成静态网页并运行服务器,通过http://localhost:4000/可以预览书籍:
setsid gitbook serve &
#服务默认端口4000,也可以指定端口启动:
setsid gitbook serve --port 4000 &
#也可以使用指定版本的方式:
setsid gitbook serve --port 4000 --gitbook=3.2.0

6.其他
6.1配置文件book.json:

{
  "title": "标题",
  "author": "作者",
  "authorHomepage": "http://www.xxx.com/",
  "description": "site description",
  "language": "zh-hans",
  "copyright": "All Rights Reserved",
  "variables": {},
  "plugins": [
    "theme-code",
    "splitter",
    "prism",
    "-font-settings",
    "folding-chapters",
    "-sharing",
    "search-pro",
    "-smart-nav-collapse",
    "include-codeblock",
    "-livereload",
    "toggle-chapters"
  ],
  "pluginsConfig": {
    "theme-default": {
      "showLevel": true
    }
  }
}

6.2插件
GitBook默认带有5个插件,highlight、search、sharing、font-settings、livereload,如果要去除自带的插件, 可以在插件名称前面加 -,比如:

"plugins": [
    "-search"
]

执行以下命令配置的插件会生成node_modules文件夹且自动下载到该目录下:

gitbook install

6.3补充
亲测gitbook的3.2.0版本不会自动首行缩进,3.2.3版本会自动增加两个空格缩进。
插件smart-nav-collapse会导致点击菜单界面频繁刷新,建议去掉配置插件时去掉即-smart-nav-collapse。

 

你可能感兴趣的:(gitbook)