GitBook安装+Docker部署
一、GitBook安装
1. 安装问题
如果此前遇到安装3.2.3一直装不上,先卸载
npm uninstall -g gitbook
npm uninsatll -g gitbook-cli
2. npm切换淘宝镜像
npm切换淘宝镜像,保证下载速度
npm config set registry https://registry.npm.taobao.org
查看是否切换成功
npm config get registry
3. 安装GitBook
npm i gitbook-cli -g
4. 初始化GitBook项目
gitbook init
它默认会给你安装3.2.3,如果一直安装不上,就停止,切换至3.0.0
gitbook fetch 3.0.0
成功后会出现:GitBook 3.0.0 has been installed
还有可能初始化不了,可能是nodejs版本问题
我一开始的版本是14X,后面卸载装10.16.3(npm版本为6.9.0)
成功后会有两个文件,这两个文件部署时一定要有
SUMMARY.md -- 文档目录
README.md -- 首页
5. 尝试启动
gitbook serve
二、GitBook配置
1. book.json
{
"title": "wade03 -文档库",
"author": "陈耿智",
"description": "陈耿智的文档库。。。",
"language": "zh-hans",
"styles": {
"website": "./public-repertory/css/gitbook-configure.css"
},
"plugins": [
"theme-comscore",
"prism",
"-highlight",
"copy-code-button",
"search-pro",
"-search",
"-lunr",
"expandable-chapters",
"splitter",
"-sharing",
"github-buttons",
"donate",
"tbfed-pagefooter",
"baidu-tongji",
"anchor-navigation-ex"
],
"pluginsConfig": {
"github-buttons": {
"buttons": [
{
"user": "CGZWade",
"repo": "wade-wx",
"type": "star",
"count": true,
"size": "small"
},
{
"user": "CGZWade",
"width": "160",
"type": "follow",
"count": true,
"size": "small"
}
]
},
"donate": {
"button": "打赏",
"alipayText": "支付宝打赏",
"wechatText": "微信打赏",
"alipay": "",
"wechat": ""
},
"prism": {
"css": [
"prismjs/themes/prism-solarizedlight.css"
],
"lang": {
"shell": "bash"
}
},
"tbfed-pagefooter": {
"copyright": "Copyright © wade 2020",
"modify_label": "该文件修订时间:",
"modify_format": "YYYY-MM-DD HH:mm:ss"
},
"baidu-tongji": {
"token": "55e7dfe47f4dc1c018d4042fdfa62565"
},
"anchor-navigation-ex": {
"showLevel": false
}
}
}
安装 GitBook 依赖:
gitbook install
解析:
title:网站标题author:网站作者description:网站功能描述language:网站使用语言styles:网站额外配置的样式表plugins:网站使用的插件pluginsConfig:网站使用的插件的额外配置
2. 去除Published with GitBook
在所在项目中创建_layouts->website->summary.html
summary.html :
{% macro articles(_articles) %}
{% for article in _articles %}
<li class="chapter {% if article.path == file.path and not article.anchor %}active{% endif %}" data-level="{{ article.level }}" {% if article.path %}data-path="{{ article.path|resolveFile }}"{% endif %}>
{% if article.path and getPageByPath(article.path) %}
<a href="{{ article.path|resolveFile }}{{ article.anchor }}">
{% elif article.url %}
<a target="_blank" href="{{ article.url }}">
{% else %}
<span>
{% endif %}
{% if article.level != "0" and config.pluginsConfig['theme-default'].showLevel %}
<b>{{ article.level }}.</b>
{% endif %}
{{ article.title }}
{% if article.path or article.url %}
</a>
{% else %}
</span>
{% endif %}
{% if article.articles.length > 0 %}
<ul class="articles">
{{ articles(article.articles, file, config) }}
</ul>
{% endif %}
</li>
{% endfor %}
{% endmacro %}
<ul class="summary">
{% set _divider = false %}
{% if config.links.sidebar %}
{% for linkTitle, link in config.links.sidebar %}
{% set _divider = true %}
<li>
<a href="{{ link }}" target="_blank" class="custom-link">{{ linkTitle }}</a>
</li>
{% endfor %}
{% endif %}
{% if _divider %}
<li class="divider"></li>
{% endif %}
{% for part in summary.parts %}
{% if part.title %}
<li class="header">{{ part.title }}</li>
{% elif not loop.first %}
<li class="divider"></li>
{% endif %}
{{ articles(part.articles, file, config) }}
{% endfor %}
<li class="divider"></li>
<!--<li>-->
<!--<a href="https://www.gitbook.com" target="blank" class="gitbook-link">-->
<!--{{ "GITBOOK_LINK"|t }}-->
<!--</a>-->
<!--</li>-->
</ul>
三、Docker部署
1. 打包
gitbook build
成功后所在目录有个_book文件夹
2. 打包成镜像
-
将
_book文件夹拷贝到你要部署的地方 -
在
_book文件夹里编写DockerfileFROM nginx WORKDIR /usr/share/nginx/html ADD . /usr/share/nginx/html EXPOSE 80 -
cmd切换至文件所在目录,build
docker build -t wade03 .查看是否有该镜像
docker images -
运行
docker run -p 4000:80 --name wade03-666 -d wade03输入网址
http://localhost:4000/,查看是否成功也可以运行:docker ps,查看是否运行
参考:https://juejin.im/post/5ce51e126fb9a07ed440d7d0
699

被折叠的 条评论
为什么被折叠?



