GitBook
GitBook安装的前提条件
# 我已有node;以及nvm(node version manager),我切换低版本即可
# 查看当前版本
node -v
# 当前本地已安装所有版本列表
nvm list
# 查看可安装的Node.js版本
nvm list available
### 报错:由于npm.taobao.org域名HTTPS证书到期更换为npmmirror.com
Could not retrieve https://npm.taobao.org/mirrors/node/index.json.
Get "https://npm.taobao.org/mirrors/node/index.json": x509: certificate has expired or is not yet valid;
-----------------------------------------------------------------------------------------------
### 一、去NVM的配置文件中:切换镜像
# 1、获取配置文件的位置
C:\Windows\system32>nvm root
Current Root: D:\Java\node_nvm\nvm\nvm
# 2、进入目录查看settins.txt
root: D:\Java\node_nvm\nvm\nvm
path: D:\Java\node
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/
===> 修改为:
root: D:\Java\node_nvm\nvm\nvm
path: D:\Java\node
node_mirror: https://npmmirror.com/mirrors/node/
npm_mirror: https://npmmirror.com/mirrors/npm/
### 二、修改npm的配置
# 1、获取配置文件的位置
C:\Windows\system32>npm config get userconfig
C:\Users\Badow.npmrc
# 2、使用shell命令来修改 或者配置文件中改。
C:\Windows\system32>npm config set registry https://registry.npmmirror.com
配置文件内容修改后:
registry=https://registry.npmmirror.com
-----------------------------------------------------------------------------------------------
# 查看可安装的Node.js版本 不是完整的;完整的得去官网找。
C:\Windows\system32>nvm list available
| CURRENT | LTS | OLD STABLE | OLD UNSTABLE |
|--------------|--------------|--------------|--------------|
| 22.9.0 | 20.17.0 | 0.12.18 | 0.11.16 |
| 22.8.0 | 20.16.0 | 0.12.17 | 0.11.15 |
| 22.7.0 | 20.15.1 | 0.12.16 | 0.11.14 |
| 22.6.0 | 20.15.0 | 0.12.15 | 0.11.13 |
| 22.5.1 | 20.14.0 | 0.12.14 | 0.11.12 |
| 22.5.0 | 20.13.1 | 0.12.13 | 0.11.11 |
| 22.4.1 | 20.13.0 | 0.12.12 | 0.11.10 |
| 22.4.0 | 20.12.2 | 0.12.11 | 0.11.9 |
| 22.3.0 | 20.12.1 | 0.12.10 | 0.11.8 |
| 22.2.0 | 20.12.0 | 0.12.9 | 0.11.7 |
| 22.1.0 | 20.11.1 | 0.12.8 | 0.11.6 |
| 22.0.0 | 20.11.0 | 0.12.7 | 0.11.5 |
| 21.7.3 | 20.10.0 | 0.12.6 | 0.11.4 |
| 21.7.2 | 20.9.0 | 0.12.5 | 0.11.3 |
| 21.7.1 | 18.20.4 | 0.12.4 | 0.11.2 |
| 21.7.0 | 18.20.3 | 0.12.3 | 0.11.1 |
| 21.6.2 | 18.20.2 | 0.12.2 | 0.11.0 |
| 21.6.1 | 18.20.1 | 0.12.1 | 0.9.12 |
| 21.6.0 | 18.20.0 | 0.12.0 | 0.9.11 |
| 21.5.0 | 18.19.1 | 0.10.48 | 0.9.10 |
# 下载 低版本:10.24.1
C:\Windows\system32>nvm install 10.24.1
Downloading node.js version 10.24.1 (64-bit)...
Complete
Creating D:\Java\node_nvm\nvm\nvm\temp
Downloading npm version 6.14.12... Complete
Installing npm v6.14.12...
Installation complete. If you want to use this version, type
nvm use 10.24.1
# 当前本地已安装所有版本列表
C:\Windows\system32>nvm list
14.18.1
* 12.16.3 (Currently using 64-bit executable)
10.24.1
# 切换版本
C:\Windows\system32>nvm use 10.24.1
Now using node v10.24.1 (64-bit)
GitBook的安装
# 1、全局安装GitBook
npm install gitbook-cli -g
# 2、查看gitbook版本号
C:\Windows\system32>gitbook -V
CLI version: 2.3.2
Installing GitBook 3.2.3
GitBook的基础
初始化
# 初始化一本书
D:_wangdao.My_summarys>gitbook init
warn: no summary file in this book
info: create README.md
info: create SUMMARY.md
info: initialization is finished
生成两个文件:README.md 是说明文档,SUMMARY.md 是书的章节目录。
运行
# 运行一本书
D:_wangdao.My_summarys>gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...
info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 1 pages
info: found 0 asset files
info: >> generation finished with success in 0.5s !
Starting server ...
Serving book on http://localhost:4000
运行在 localhost:4000,可访问。
并生成了_book文件夹
GitBook的实战
SUMMARY.md
# Summary
* [平台简介](README.md)
* [1 平台架构](content/structure/index.md)
* [2 平台能力](content/ability/index.md)
* [2.1 能力说明](content/ability/collect_description.md)
* [2.2 监控指标](content/ability/metrics_description/index.md)
上述为我定义的目录结构。
README.md
# 平台简介
<img src='images\introduction-indexUp.png'><img src='images\introduction-indexDown.png'>
README.md 即最终生成,默认打开的页面。
遇到的坑
-
同时使用
chapter-fold,expandable-chapters-small导致了折叠的那个【作为目录展开项】 不可跳转例如:上述的 content/ability/index.md、content/platform_access/index.md,无法实现跳转。。。。不知为何。
-
引用的图片路径不要拼接
/;这样会导致去根目录上获取图片,以及定义LOGO图片路径的地方也要注意。我在md文件中的引用图片样例:
<img src='images/xxx.png'>我解决方案是:每个路径下都创建一个 images 文件夹,方便管理以及引用,且下边都有
logo.png这样图标LOGO才能不丢。"pluginsConfig": { "insert-logo": { "url": "images/logo.png", "style": "background: none; max-height: 30px; min-height: 30px" } } -
本地打包之后,浏览本地文档,搜索会一直报错。search_plus_index.json 无法调用。
/D:/Git-Book-busiMonitor/_book/index.html:1 Access to XMLHttpRequest at 'file:///D:/Git-Book-busiMonitor/_book/search_plus_index.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: chrome-extension, chrome-untrusted, data, edge, http, https, isolated-app. /D:/Git-Book-busiMonitor/_book/search_plus_index.json:1 Failed to load resource: net::ERR_FAILED无需管它,后续部署时候是可行的。
-
未解之谜:关于默认存在的插件,反而不生效。例如:页面上的目录隐藏、A字体调整,都点击不触发。。。有知道的么?求助......
GitBook的镜像部署
具体操作
- 将打包生成的
_book文件夹下的内容,全部放在创建好的一个文件夹下。
-
书写dockerfile文件 暴露端口号为80。 注:此时
Dockerfile与guide文件夹同级。FROM nginx:1.22.0 WORKDIR /usr/share/nginx/html ADD . /usr/share/nginx/html EXPOSE 80 -
打镜像、运行即可。