如果此前遇到安装3.2.3一直装不上,先卸载
npm uninstall -g gitbook
npm uninsatll -g gitbook-cli
npm切换淘宝镜像,保证下载速度
npm config set registry https://registry.npm.taobao.org
查看是否切换成功
npm config get registry
npm i gitbook-cli -g
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 -- 首页
gitbook serve
{
"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
:网站使用的插件的额外配置在所在项目中创建_layouts->website->summary.html
summary.html :
{% macro articles(_articles) %}
{% for article in _articles %}
{% 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>
ul>
gitbook build
成功后所在目录有个_book
文件夹
将_book
文件夹拷贝到你要部署的地方
在_book
文件夹里编写Dockerfile
FROM 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