安装GitBook
安装GitBook之前,要确认本地已经安装好node.js
如下图所示:
全局安装GitBook :
npm install gitbook-cli -g
检验是否安装成功:
GitBook的初步使用
初始化一本书
gitbook init
生成如下文件:
解释:
- README.md 说明文件。
- SUMMARY.md 左侧菜单目录结构文件。
运行这本书
gitbook serve
如下图所示:
浏览器访问效果图如下所示:
构建静态网站
gitbook build
上面的命令执行后会在根目录生成一个文件夹_book,里面的文件如下:
配置文件book.json
该文件需要自行创建。如下结构:
{
"title": "一切皆往事",
"author": "往事",
"description": "书中自有往事",
"language": "zh-hans",
"gitbook": "3.2.3",
"plugins":[
"expandable-chapters-small",
"search-plus",
"sharing",
"splitter",
"anchor-navigation-ex-toc",
"hide-element"
]
}
相关信息解释:
title:标题信息。author作者信息。description书的描述。language设置展示的语言。gitbook这本书的版本。plugins里是GitBook的插件。配置好之后,要先使用gitbook install进行插件的安装。然后再执行gitbook serve即可看到效果了。
gitbook install之后,会发现目录多出了一个文件夹名为node_modules 如下图所示:
常用插件
插件描述
-
expandable-chapters-small: 章节导航支持多级目录,并配置箭头图标,点击箭头才能实现收放目录。 -
search-plus:高级搜索,支持中文,使用该插件,需要将默认的lunr和search禁用掉,即-lunr和-search -
sharing:分享插件,默认开启。 -
splitter:扩展导航侧边栏,支持宽度可调节。 -
anchor-navigation-ex-toc:为文章增加锚点目录栏及回到顶部功能。 -
hide-element:隐藏元素。如:隐藏某个链接。 -
insert-logo:左侧导航栏上方插入Logo图。 -
mygitalk 基于gitalk的评论插件 ➡️ github.com/snowdreams1…
-
theme-default GitBook的默认主题 ➡️ github.com/GitbookIO/t…
-
autotheme 自动换肤插件 ➡️ github.com/willin/gitb…
-
sharing 默认的分享插件 ➡️ github.com/GitbookIO/p…
-
fontsettings 默认的字体、字号、颜色设置插件 ➡️ github.com/GitbookIO/p…
-
highlight 默认的代码高亮插件,通常会使用 prism 来替换 ➡️ github.com/GitbookIO/p…
-
search 默认搜索插件 ➡️ github.com/GitbookIO/p…
-
search-plus 支持中文搜索插件 ➡️ github.com/lwdgit/gitb…
-
prism 基于 Prism 的代码高亮 ➡️ github.com/gaearon/git…
-
favicon 更改网站的 favicon.ico ➡️ github.com/menduo/gitb…
-
github 在右上角显示 github 仓库的图标链接 ➡️ github.com/GitbookIO/p…
-
github-buttons 显示 github 仓库的star和fork按钮 ➡️ github.com/azu/gitbook…
-
splitter 在左侧目录和右侧内容之间添加一个可以拖拽的栏,用来调整两边的宽度 ➡️ github.com/yoshidax/gi…
-
copy-code-button 为代码块添加复制的按钮 ➡️ github.com/WebEngage/g…
-
tbfed-pagefooter 自定义页脚,显示版权和最后修订时间 ➡️ github.com/zhj3618/git…
-
expandable-chapters 收起或展开章节目录中的父节点 ➡️ github.com/DomainDrive…
-
expandable-chapters-small 比较好的折叠侧边栏 ➡️ github.com/lookdczar/g…
-
book-summary-scroll-position-saver 自动保存左侧目录区域导航条的位置 ➡️ github.com/yoshidax/gi…
-
ga 添加 Google 统计代码 ➡️ github.com/GitbookIO/p…
-
sitemap 生成站点地图 ➡️ github.com/GitbookIO/p…
-
baidu 使用百度统计 ➡️ github.com/poppinlp/gi…
-
Donate Gitbook 捐赠打赏插件 ➡️ github.com/willin/gitb…
-
anchors 标题带有 github 样式的锚点 ➡️ github.com/rlmv/gitboo…
-
anchor-navigation-ex 插件锚导航-EX ➡️ github.com/zq99299/git…
-
theme-api 编写 API 文档 ➡️ github.com/GitbookIO/t…
-
katex 使用KaTex进行数学排版 ➡️ github.com/GitbookIO/p…
-
editlink 内容顶部显示编辑本页链接 ➡️ github.com/zhaoda/gitb…
-
ad 在每个页面顶部和底部添加广告或任何自定义内容 ➡️ github.com/zhaoda/gitb…
-
image-captions 抓取内容中图片的alt或title属性,在图片下面显示标题 ➡️ github.com/todvora/git…
-
chart 使用 C3.js 图表 ➡️ github.com/csbun/gitbo…
-
styles-sass 使用 SASS 替换 CSS ➡️ github.com/GitbookIO/p…
-
styles-less 使用 LESS 替换 CSS ➡️ github.com/GitbookIO/p…
-
disqus 添加 disqus 评论插件 ➡️ github.com/GitbookIO/p…
-
latex-codecogs 使用数学方程式 ➡️ github.com/GitbookIO/p…
-
mermaid 使用流程图 ➡️ github.com/JozoVilcek/…
-
atoc 插入 TOC 目录 ➡️ github.com/willin/gitb…
-
ace 插入代码高亮编辑器 ➡️ github.com/ymcatar/git…
-
sectionx 分离各个段落,并提供一个展开收起的按钮 ➡️ github.com/ymcatar/git…
-
mcqx 交互式多选插件 ➡️ github.com/ymcatar/git…
-
include-codeblock 通过引用文件插入代码 ➡️ github.com/azu/gitbook…
-
fbqx 使用填空题 ➡️ github.com/Erwin-Chan/…
-
spoiler 隐藏答案,当鼠标划过时才显示 ➡️ github.com/ymcatar/git…
-
anchor-navigation 锚点导航 ➡️ github.com/yaneryou/gi…
-
youtubex 插入 YouTube 视频 ➡️ github.com/ymcatar/git…
-
redirect 重定向页面跳转 ➡️ github.com/ketan/gitbo…
-
duoshuo 使用多说评论 ➡️ github.com/codepiano/g…
-
jsfiddle 插入 JSFiddle 组件 ➡️ github.com/Mavrin/gitb…
-
jsbin 插入 JSBin 组件 ➡️ github.com/jcouyang/gi…
-
Advanced Emoji 支持emoji表情 ➡️ github.com/codeclou/gi…
-
Puml 使用 PlantUML 展示 uml 图 ➡️ github.com/GitbookIO/p…
-
Graph 使用 function-plot 绘制数学函数图 ➡️ github.com/cjam/gitboo…
-
Todo 添加 Todo 功能 ➡️ github.com/ly-tools/gi…
-
include-csv 展示 csv 文件内容 ➡️ github.com/TakuroFukam…
-
musicxml 支持 musicxml 格式的乐谱渲染 ➡️ github.com/ymcatar/git…
-
versions-select 添加版本选择的下拉菜单,针对文档有多个版本的情况 ➡️ github.com/prescottpru…
-
rss 添加 rss 订阅功能 ➡️ github.com/denysdovhan…
-
multipart 将书籍分成几个部分 ➡️ github.com/citizenmatt…
-
url-embed 嵌入动态内容 ➡️ github.com/basilvetas/…
注意:每次添加一次新的插件后,要进行安装gitbook install。
去除插件
可以在插件名称前面加 - 如下:
"plugins":[
"-lunr",
"-search"
]
隐藏导航菜单下方的链接
如下图所示:
使用hide-element插件。在book.json中加入:
{
"title": "一切皆往事",
"author": "往事",
"description": "书中自有往事",
"language": "zh-hans",
"gitbook": "3.2.3",
"plugins":[
"expandable-chapters-small",
"search-plus",
"sharing",
"splitter",
"anchor-navigation-ex-toc",
"hide-element",
"-lunr",
"-search"
],
"pluginsConfig": {
"hide-element": {
"elements": [".gitbook-link"]
}
}
}
pluginsConfig这个是主要的。
导航上方Logo
这个要使用到insert-logo插件。相关信息如下:
{
"title": "一切皆往事",
"author": "往事",
"description": "书中自有往事",
"language": "zh-hans",
"gitbook": "3.2.3",
"plugins":[
"expandable-chapters-small",
"search-plus",
"sharing",
"splitter",
"anchor-navigation-ex-toc",
"hide-element",
"-lunr",
"-search"
],
"pluginsConfig": {
"hide-element": {
"elements": [".gitbook-link"]
},
"insert-logo": {
"url": "images/logo.png"
"style": "background:none;max-height:120px;min-height:120px;"
}
}
}
多级菜单编写
修改SUMMARY.md文件,内容如下:
* [说明文档](README.md)
* [第一章](Demo/demo1.md)
- [1.1. 我来了](Demo/demo2.md)
- [1.1.1 我又来了](Demo/demo2.md)
在SUMMARY.md同级目录下自行在创建Demo文件夹,里面再创建两个文件:demo1.md和demo2.md
执行命令gitbook serve后如下图所示: