Gitbook使用教程

Gitbook安装

Node.js的安装,这里就不多说了。

1
2
3

p{width:100px;}

kimbie.dark css
1
p{width:100px;}

报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
npm WARN  checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

报错原因是:Mac 安装 npm 的全局包,报错没有权限。

解决方法:在安装命令前加上sudo,输入用户的登陆密码,提升权限进行安装。

1
sudo npm install gitbook-cli -g

安装成功后,执行gitbook -V查看版本信息。此命令会默认同时安装 GitBook。

至此,安装成功。

问题:TypeError: cb.apply is not a function

解决办法:按照提示中的路径,/usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js 打开polyfills.js文件

在第62-64行调用的这个函数注释掉

1
2
3
fs.stat = statFix(fs.stat)
fs.fstat = statFix(fs.fstat)
fs.lstat = statFix(fs.lstat)

问题: 执行 gitbook -V 时显示:Installing GitBook 3.2.3 …….,之后出现长时间卡顿
解决办法1: 科学上网
解决办法2: 切换为使用国内速度较快的淘宝镜像

1
npm config set registry=http://registry.npm.taobao.org -g

GitBook初始化

打开一个文件夹 MyGitBook,使用 gitbook init 初始化文件夹,会自动生成两个必要的文件 README.md 和 SUMMARY.md。

README.md: 书的介绍文字,如前言、简介,在章节中也可做为章节的简介。
SUMMARY.md: 定制书籍的章节结构和顺序。

1
gitbook init

_book 是默认的输出目录,存放着原始 markdown 渲染完毕后的 html 文件,可以直接打包到服务器充当静态网站使用.一般是执行 gitbook build 或 gitbook serve 自动生成的.

启动服务:

1
github serve

插件

gitbook插件

在插件名字前面加一个减号”-“即可对插件禁用。