配置
GitBook允许您使用灵活的配置来自定义您的书。这些选项在book.json
文件中指定。对于不熟悉JSON语法的作者,您可以使用JSONlint之类的工具来验证语法。
常规设置
变量 | 说明 |
---|---|
root |
包含所有图书文件的根文件夹的路径,除了book.json |
structure |
指定自述,摘要,词汇表等的路径。请参见结构段落. |
title |
书的标题,默认值从README中提取。在GitBook.com上,此字段已预填。 |
description |
您的图书说明,默认值从自述文件中提取。在GitBook.com上,此字段已预填。 |
author |
作者姓名。在GitBook.com上,此字段已预填。 |
isbn |
书的国际码ISBN |
language |
图书语言的ISO代码 ,默认值是en |
direction |
文本的方向。可以是rtl 或ltr ,默认值取决于language 的值 |
gitbook |
GitBook的版本。使用SemVer规范并接受诸如“> = 3.0.0” 的条件 |
其他属性设置
links
: 在左侧导航栏添加链接信息{ "links": { "sidebar": { "Home": "https://www.baidu.com" } } }
styles
: 自定义页面样式, 默认情况下各generator对应的css文件{ "styles": { "website": "styles/website.css", "ebook": "styles/ebook.css", "pdf": "styles/pdf.css", "mobi": "styles/mobi.css", "epub": "styles/epub.css" } }
例如使
<h1>
<h2>
标签有下边框, 可以在website.css
中设置h1 , h2{ border-bottom: 1px solid #EFEAEA; }
结构体
除了root
变量,你可以告诉Gitbook Readme,Summary,Glossary,Languages的文件名(而不是使用默认名称,如README.md)。 这些文件必须在您的书的根(或每个语言书的根)。不接受诸如dir/MY_README.md
之类的路径。
变量 | 说明 |
---|---|
structure.readme |
自述文件名(默认为README.md ) |
structure.summary |
摘要文件名(默认为SUMMARY.md ) |
structure.glossary |
词汇表文件名(默认为GLOSSARY.md ) |
structure.languages |
语言文件名(默认为LANGS.md ) |
PDF选项
PDF输出可以使用book.json
中的一组选项来定制:
变量 | 说明 |
---|---|
pdf.pageNumbers |
在每页底部添加页码(默认为true ) |
pdf.fontSize |
基本字体大小(默认为12 ) |
pdf.fontFamily |
基本字体系列(默认为Arial ) |
pdf.paperSize |
纸张尺寸,选项为 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'legal', 'letter' (默认为 a4 ) |
pdf.margin.top |
上边距 (默认为 56 ) |
pdf.margin.bottom |
底边距 (默认为 56 ) |
pdf.margin.right |
右边距 (默认为 62 ) |
pdf.margin.left |
左边距 (默认为 62 ) |
词汇表
您可以指定要显示为注释的术语及其相应的定义。 基于这些术语,GitBook在编译的时候会自动构建索引并在页面中突出显示这些术语。
GLOSSARY.md
是一个h2
标题的列表,以及一个描述段落:
## 条款
该术语的定义
## 另一个名词
使用它的定义,它可以包含粗体文本
以及所有其他类型的内联标记...
多种语言
GitBook支持多种语言编写的书籍或者文档。 首先需要在根目录创建一个名为LANGS.md
的文件,然后按照语言创建子目录:
# Languages
* [中文](zh/)
* [English](en/)
* [French](fr/)
* [Español](es/)
每种语言的配置
每个语言(例如:en
)目录中都可以有一个book.json
来定义自己的配置,它将作为主配置的扩展。
唯一的例外是插件,插件是全局指定的,语言环境配置不能指定特定的插件。
Markdown语法
Markdown
是GitBook的默认解析器,本文档基本上都是Markdown语法编写的。当然,你也可以选择AsciiDoc语法来编写文档。
AsciiDoc
从·2.0.0·版本开始,GitBook接受AsciiDoc语法文件作为输入格式。
有关格式的更多信息,请参阅AsciiDoc语法快速参考。
跟markdown一样,GitBook可以从下的面文件来提取结构:README.adoc
,SUMMARY.adoc
,LANGS.adoc
和GLOSSARY.adoc
。
插件
可以通过 Gitbook 的插件来扩展 Gitbook 的功能,现有的 Gitbook 插件能够实现数学公式,Google 统计,评论等等功能。
所有的插件都可以从 https://plugins.gitbook.com/ 获取。
变量 | 说明 |
---|---|
plugins |
要加载的插件列表 |
pluginsConfig |
插件配置 |
安装插件
Gitbook 安装插件比较简单,需要在项目下添加 book.json
文件,然后在其中添加
{
"plugins": ["plugins1", "plugins2"],
"pluginsConfig": {
"plugins1": {}
}
}
注册完插件之后,可以通过下面的命令来安装插件
gitbook install
Gitbook默认自带5个插件
- highlight:代码高亮,通常会使用 prism 来替换
- search:导航栏查询功能(不支持中文),所以通常会使用 search-pro 来替换
- sharing:右上角分享功能
- font-settings:字体设置(最上方的"A"符号)
- livereload:为GitBook实时重新加载
[!Tip] 可以在插件名称前面加 - 去除自带插件,例如常用去除自带搜索 "plugins": [ "-search" ]
常用的插件
下面列举一些常用的gitbook插件,至于怎么加上自己开发的插件,这里就不多说了,感兴趣的可以看这篇中文文档。
用法:在book.json
中添加以下内容。然后执行gitbook install
,或者使用NPM
安装(单独安装推荐NPM)npm install gitbook-plugin-插件名
,也可以从源码GitHub地址中下载,放到node_modules
文件夹里(GitHub地址在进入插件地址右侧的GitHub链接)
修改页面样式
ad
在每个页面顶部和底部添加广告或任何自定义内容 ➡️ https://github.com/zhaoda/gitbook-plugin-adAdvanced Emoji
支持emoji表情 ➡️ https://github.com/codeclou/gitbook-plugin-advanced-emojianchors
标题带有 github 样式的锚点 ➡️ https://github.com/rlmv/gitbook-plugin-anchorsanchor-navigation
锚点导航 ➡️ https://github.com/yaneryou/gitbook-plugin-anchor-navigationanchor-navigation-ex
插件锚导航-EX ➡️ https://github.com/zq99299/gitbook-plugin-anchor-navigation-exauto-scroll-table
表格滚动条(为避免表格过宽,增加滚动条) ➡️ https://www.jianshu.com/p/427b8bb066e6autotheme
自动换肤插件(早中晚自动切换) ➡️ https://github.com/willin/gitbook-plugin-autothemechange_girls
可自动切换的背景 ➡️ https://github.com/zhenchao125/gitbook-plugin-change_girlscustom-favicon
修改标题栏图标 ➡️ https://github.com/Bandwidth/gitbook-plugin-custom-faviconchapter-fold
左侧目录折叠 ➡️ https://github.com/ColinCollins/gitbook-plugin-chapter-foldexpandable-chapters
收起或展开章节目录中的父节点 ➡️ https://github.com/DomainDrivenArchitecture/gitbook-plugin-expandable-chaptersexpandable-chapters-small
折叠侧边栏 ➡️ https://github.com/lookdczar/gitbook-plugin-expandable-chapters-small-auto[!note|label: 这三款目录折叠的区别是:]
expandable-chapters-small
和expandable-chapters
效果相同,唯一不同的是expandable-chapters
这个插件的箭头粗;
另外这两款只有点击箭头才能实现折叠扩展。不如【chapter-fold 左侧目录折叠】
好用editlink
顶部显示编辑此页 ➡️ https://github.com/zhaoda/gitbook-plugin-editlinkemphasize
为文字加上底色 ➡️ https://github.com/GitbookIO/plugin-emphasizefavicon
更改网站的 favicon.ico ➡️ https://github.com/menduo/gitbook-plugin-faviconflexible-alerts
将块引用转换为漂亮的警报 ➡️ https://github.com/zanfab/gitbook-plugin-flexible-alertsgithub-buttons
显示 github 仓库的star和fork按钮 ➡️ https://github.com/azu/gitbook-plugin-github-buttonshide-element
隐藏元素 ➡️ https://github.com/gonjay/gitbook-plugin-hide-elementinsert-logo
将logo插入到导航栏上方中 ➡️ https://github.com/matusnovak/gitbook-plugin-insert-logolocalized-footer
为 Gitbook 每一个页面添加页脚 ➡️ https://github.com/noerw/gitbook-plugin-localized-footer#readmeprism
基于 Prism 的代码高亮 ➡️ https://github.com/gaearon/gitbook-plugin-prismpage-copyright
自定义页面页脚版权(内容多) ➡️ https://github.com/skyFi/gitbook-plugin-page-footersplitter
在左侧目录和右侧内容之间添加一个可以拖拽的栏,用来调整两边的宽度 ➡️ https://github.com/yoshidax/gitbook-plugin-splitterstyles-sass
使用 SASS 替换 CSS ➡️ https://github.com/GitbookIO/plugin-styles-sassstyles-less
使用 LESS 替换 CSS ➡️ https://github.com/GitbookIO/plugin-styles-lesssectionx
分离各个段落,并提供一个展开收起的按钮 ➡️ https://github.com/ymcatar/gitbook-plugin-sectionxtbfed-pagefooter
自定义页脚,显示版权和最后修订时间 ➡️ https://github.com/zhj3618/gitbook-plugin-tbfed-pagefootertheme-fexa
基于gitbook主题机制定制的主题 ➡️ https://github.com/tonyyls/gitbook-plugin-theme-fexa
功能增强
ace
插入代码高亮编辑器 ➡️ https://github.com/ymcatar/gitbook-plugin-aceatoc
插入 TOC 目录 ➡️ https://github.com/willin/gitbook-plugin-atocaccordion
手风琴,可以实现将内容隐藏起来 ➡️ https://github.com/artalar/gitbook-plugin-accordionback-to-top-button
回到顶部 ➡️ https://github.com/stuebersystems/gitbook-plugin-back-to-top-buttonbook-summary-scroll-position-saver
自动保存左侧目录区域导航条的位置 ➡️ https://github.com/yoshidax/gitbook-plugin-book-summary-scroll-position-saverbaidu
使用百度统计 ➡️ https://github.com/poppinlp/gitbook-plugin-baiduclick-reveal
默认隐藏,点击可显示。 ➡️ https://github.com/c4software/gitbook-plugin-click-revealcode
代码添加行号&复制按钮 ➡️ https://github.com/davidmogar/gitbook-plugin-codecopy-code-button
为代码块添加复制的按钮 ➡️ https://github.com/WebEngage/gitbook-plugin-copy-code-buttonchart
使用 C3.js 图表 ➡️ https://github.com/csbun/gitbook-plugin-chartDonate
Gitbook 捐赠打赏插件 ➡️ https://github.com/willin/gitbook-plugin-donatedisqus
添加 disqus 评论插件 ➡️ https://github.com/GitbookIO/plugin-disqusduoshuo
使用多说评论 ➡️ https://github.com/codepiano/gitbook-plugin-duoshuoga
添加 Google 统计代码 ➡️ https://github.com/GitbookIO/plugin-gainclude-codeblock
通过引用文件插入代码 ➡️ https://github.com/azu/gitbook-plugin-include-codeblockjsfiddle
插入 JSFiddle 组件 ➡️ https://github.com/Mavrin/gitbook-plugin-jsfiddlejsbin
插入 JSBin 组件 ➡️ https://github.com/jcouyang/gitbook-plugin-jsbinmygitalk
基于gitalk的评论插件 ➡️ https://github.com/snowdreams1006/gitbook-plugin-mygitalksearch-plus
支持中文搜索插件 ➡️ https://github.com/lwdgit/gitbook-plugin-search-plussearch-pro
高级搜索(支持中文) ➡️ https://github.com/gitbook-plugins/gitbook-plugin-search-prositemap
生成站点地图 ➡️ https://github.com/GitbookIO/plugin-sitemaptheme-api
编写 API 文档 ➡️ https://github.com/GitbookIO/theme-apimcqx
交互式多选插件 ➡️ https://github.com/ymcatar/gitbook-plugin-mcqxspoiler
隐藏答案,当鼠标划过时才显示 ➡️ https://github.com/ymcatar/gitbook-plugin-spoilerredirect
重定向页面跳转 ➡️ https://github.com/ketan/gitbook-plugin-redirectpage-treeview
生成页内目录 ➡️ https://github.com/aleen42/gitbook-treeviewsimple-page-toc
生成本页目录 ➡️ https://github.com/stuebersystems/gitbook-plugin-simple-page-tocpage-toc-button
悬浮目录 ➡️ https://github.com/stuebersystems/gitbook-plugin-page-toc-buttonPuml
使用 PlantUML 展示 uml 图 ➡️ https://github.com/GitbookIO/plugin-pumlklipse
嵌入类似IDE的功能,可在代码段中实时交互,即(输入代码 > 执行结果 ➡️ https://github.com/brian-dawn/gitbook-plugin-klipseTodo
添加 Todo 功能 ➡️ https://github.com/ly-tools/gitbook-plugin-todoinclude-csv
展示 csv 文件内容 ➡️ https://github.com/TakuroFukamizu/gitbook-plugin-include-csvmusicxml
支持 musicxml 格式的乐谱渲染 ➡️ https://github.com/ymcatar/gitbook-plugin-musicxmlversions-select
添加版本选择的下拉菜单,针对文档有多个版本的情况 ➡️ https://github.com/prescottprue/gitbook-plugin-versions-selectrss
添加 rss 订阅功能 ➡️ https://github.com/denysdovhan/gitbook-plugin-rssmultipart
将书籍分成几个部分 ➡️ https://github.com/citizenmatt/gitbook-plugin-multiparturl-embed
嵌入动态内容 ➡️ https://github.com/basilvetas/gitbook-plugin-url-embedpageview-count
阅读量计数 ➡️ https://github.com/tinys/gitbook-plugin-pageview-count
查看图片
image-captions
抓取内容中图片的alt
或title
属性,在图片下面显示标题 ➡️ https://github.com/todvora/gitbook-plugin-image-captionspopup
单击图片,在新页面查看大图。 ➡️ https://github.com/somax/gitbook-plugin-popuplightbox
点击图片可显示,大小不变 ➡️ https://github.com/vongola12324/gitbook-plugin-lightbox
数学插件 & Tex
fbqx
使用填空题 ➡️ https://github.com/Erwin-Chan/gitbook-plugin-fbqxGraph
使用 function-plot 绘制数学函数图 ➡️ https://github.com/cjam/gitbook-plugin-graphkatex
使用KaTex进行数学排版 ➡️ https://github.com/GitbookIO/plugin-katexlatex-codecogs
使用数学方程式 ➡️ https://github.com/GitbookIO/plugin-latex-codecogsmathjax
支持数学方程式 ➡️ https://www.mathjax.org/mermaid
使用流程图 ➡️ https://github.com/JozoVilcek/gitbook-plugin-mermaid
[!note|label: MathJax 和 KaTeX 的区别]
mathjax
和katex
插件是 Tex 公式绘制的不同实现,它们基于各自的开源库:KaTeX 和 MathJax 。
MathJax 支持整个 Tex 语法,但是在制作电子书版本时不是很完美。 KaTex 在所有格式(网页和电子书)的绘制上都很完美,但是还不支持 所有的语法。
更多其他插件选择
- https://www.cnblogs.com/mingyue5826/p/10307051.html
- https://www.jianshu.com/p/53fccf623f1c
- https://www.jianshu.com/p/427b8bb066e6
book.json配置(直接用本书配置来说明)
{
"title": "hqbook",
"author": "Haoqiang Chen",
"description": "平时零散编程笔记收录手册,以便日后查阅。",
"keywords": "编程,markdown,笔记",
"introduction": {
"path": "README.md",
"title": "hqbook"
},
"links": {
"home": false,
"about": false,
"issues": false,
"contribute": false,
"tail": {
"GitHub地址": "https://github.com/HaoqiangChen/hqbook"
},
"gitbook": false,
"sharing": {
"google": true,
"facebook": true,
"twitter": true,
"weibo": true,
"qrcode": true
}
},
"variables": {
"themeColor": "#3884ff",
"themeHqbook": {
"nav": [
{
"url": "https://www.baidu.com",
"target": "_blank",
"name": "百度一下"
},
{
"url": "https://jsrun.net/",
"target": "_blank",
"name": "JSRUN"
},
{
"url": "https://www.runoob.com/",
"target": "_blank",
"name": "菜鸟教程"
},
{
"url": "https://www.atool99.com/",
"target": "_blank",
"name": "ATOOL在线工具"
}
]
}
},
"plugins": [
"-highlight",
"-lunr",
"-search",
"theme-hqbook",
"chapter-fold",
"flexible-alerts",
"prism",
"search-pro",
"sitemap"
],
"pluginsConfig": {
"fontSettings": {
"theme": "white",
"family": "serif",
"size": 1
},
"chapter-fold": {},
"flexible-alerts": {
"style": "flat",
"note": {
"label": "笔记"
},
"tip": {
"label": "提示"
},
"warning": {
"label": "警告",
"icon": "fa fa-warning"
},
"danger": {
"label": "注意",
"icon": "fa fa-exclamation-triangle"
}
},
"localized-footer": {
"hline": true,
"filename": "./FOOTER.md"
},
"prism": {
"css": [
"gitbook-plugin-theme-hqbook/_themes/prism-xonokai.css"
]
},
"styles": {
"website": "styles/website.css"
},
"theme-hqbook": {
"copyLines": false,
"hide-elements": [
".summary .gitbook-link"
],
"flexible-linkcard": {
"title": "Converts blockquotes into beautiful linkcard, custom nice links",
"hrefUrl": "https://github.com/HaoqiangChen/hqbook",
"imgSrc": "../../images/home/logo.png"
}
},
"sitemap": {
"hostname": "https://haoqiangchen.github.io/hqbook/"
}
},
"pdf": {
"toc": true,
"pageNumbers": true,
"fontSize": 12,
"paperSize": "a4",
"margin": {
"right": 62,
"left": 62,
"top": 36,
"bottom": 36
}
}
}