gitbook教程
链接
文字链接语法
[這是連結](http://cowmanchiang.me/gitbook)
注解方式语法
[這是連結][1]
[1]: http://cowmanchiang.me/gitbook
gitbook 书籍编排
npm install gitbook -g 错误
npm install -g gitbook-cli 正确
gitbook init // 初始化书籍目录
gitbook serve // 编译书籍
gitbook install ./ //安装book.json文件里指定插件
gitbook build //将书籍内容输出到默认_book目录
目录结构
SUMMARY.md
* [前言](introduct/README1.md)
- [API索引](introduct/index.md)
- [简介](introduct/about.md)
* [你好 Regular](getting-start/README.md)
- [安装](getting-start/install.md)
- [快速起步](getting-start/quirk-example.md)
- [小结](getting-start/review.md)
多语言版本
LANGS.md 放置在根目录
[English](en/)
[French](fr/)
[Español](es/)
REAME.md
REAME相当于书籍的前言部分。
封面
封面文件 /cover.jpg 尺寸为 1800x2360. 封面的小尺寸图 /cover_small.png
词汇表
允许你列出条目以及它们的定义. 基于这些条目 gitbook会自动创建一个索引,并在页面中加亮这些条目. GLOSSARY.md 格式很简单 :
# term
Definition for this term
# Another term
With it's definition, this can contain bold text and all other kinds of inline markup ...
忽略文件与文件夹
.gitignore, .bookignore .ignore 得到需要忽略的文件/文件夹的列表. (文件的格式和 .gitignore一样).
.gitignore最佳实践是忽略build文件,这些文件来自 node.js (node_modules, ...) 和GitBook的build文件: _book, .epub, .mobi and *.pdf.
book.json 配置文件
{
// 输出文件夹
// 注意: 它会覆盖命令行传入的参数
// 不建议在此文件中配置
"output": null,
// 产生的书籍的类型
// 注意: 它会覆盖命令行传入的参数
// 不建议在此文件中配置
"generator": "site",
// 图书标题和描述 (默认从README抽取)
"title": null,
"description": null,
// 对于ebook格式, 扩展名the extension to use for generation (default is detected from output extension)
// "epub", "pdf", "mobi"
// 注意: 它会覆盖命令行传入的参数
// 不建议在此文件中配置
"extension": null,
// GitHub 信息(defaults are extracted using git)
"github": null,
"githubHost": "https://github.com/",
// 插件列表, can contain "-name" for removing default plugins
"plugins": [],
// 插件通用配置
"pluginsConfig": {
"fontSettings": {
"theme": "sepia", "night" or "white",
"family": "serif" or "sans",
"size": 1 to 4
}
},
// 模版中的链接 (null: default, false: remove, string: new value)
"links": {
// Custom links at top of sidebar
"sidebar": {
"Custom link name": "https://customlink.com"
},
// Sharing links
"sharing": {
"google": null,
"facebook": null,
"twitter": null,
"weibo": null,
"all": null
}
},
// PDF 参数
"pdf": {
// Add toc at the end of the file
"toc": true,
// Add page numbers to the bottom of every page
"pageNumbers": false,
// Font size for the fiel content
"fontSize": 12,
// Paper size for the pdf
// Choices are [u’a0’, u’a1’, u’a2’, u’a3’, u’a4’, u’a5’, u’a6’, u’b0’, u’b1’, u’b2’, u’b3’, u’b4’, u’b5’, u’b6’, u’legal’, u’letter’]
"paperSize": "a4",
// Margin (in pts)
// Note: 72 pts equals 1 inch
"margin": {
"right": 62,
"left": 62,
"top": 36,
"bottom": 36
}
}
}
ebook-convert 电子书格式转换
npm install ebook-convert
使用插件
Gitbook 本身功能丰富,但同时可以使用插件来进行个性化定制。Gitbook 插件 里已经有100多个插件,可以在 book.json 文件的 plugins 和 pluginsConfig 字段添加插件及相关配置,添加后别忘了进行安装。
// book.json
{
"title": "Webpack 中文指南",
"description": "Webpack 是当下最热门的前端资源模块化管理和打包工具,本书大部分内容翻译自 Webpack 官网。",
"language": "zh",
"plugins": [
"disqus",
"github",
"edit-link",
"prism",
"-highlight",
"baidu",
"splitter",
"sitemap"
],
"pluginsConfig": {
"disqus": {
"shortName": "webpack-handbook"
},
"github": {
"url": "https://github.com/zhaoda/webpack-handbook"
},
"edit-link": {
"base": "https://github.com/zhaoda/webpack-handbook/blob/master/content",
"label": "编辑本页"
},
"baidu": {
"token": "a9787f0ab45d5e237bab522431d0a7ec"
},
"sitemap": {
"hostname": "http://zhaoda.net/"
}
}
}
安装插件
$ gitbook install ./
常用插件
插件 | 简介 |
---|---|
ad | 在每个页面顶部和底部添加广告或任何自定义内容 |
splitter | 在左侧目录和右侧内容之间添加一个可以拖拽的栏,用来调整两边的宽度 |
anchors | 标题带有 github 样式的锚点 |
edit-link | 内容顶部显示 编辑本页 链接 |
chart | 使用 C3.js 图表 |
ga | 添加 Google 统计代码 |
disqus | 添加 disqus 评论插件 |
sitemap | 生成站点地图 |
latex-codecogs | 使用数学方程式 |
mermaid-2 | 使用流程图 |
book-summary-scroll-position-saver | 自动保存左侧目录区域导航条的位置 |
JS Sequence Diagram | 生成序列图的插件 |
tbfed-pagefooter | 自定义页脚,显示版权和最后修订时间 |
prism | 基于 Prism 的代码高亮 |
atoc | 插入 TOC 目录 |
ace | 插入代码高亮编辑器 |
mcqx | 使用选择题 |
fbqx | 使用填空题 |
spoiler | 隐藏答案,当鼠标划过时才显示 |
exercises | 添加可交互的习题 |
quizzes | 添加可交互的选择题 |
mathjax | 添加数学表达式支持 |
include-codeblock | 通过引用文件插入代码 |
anchor-navigation | 锚点导航 |
redirect | 页面跳转 |
expandable-chapters | 收起或展开章节目录中的父节点 |
baidu | 使用百度统计 |
duoshuo | 使用多说评论 |
jsfiddle | 插入 JSFiddle 组件 |
jsbin | JSBin 组件,在 GitBook 中嵌入 JS 终端 |
Autocover | 自动生成书本封面 |
Transform annoted quotes to notes | 对 Markdown 引用进行二次渲染 |
Bootstrap JavaScript | 使用 Bootstrap JavaScript 插件 |
image-captions | 抓取内容中图片的 alt 或 title 属性,在图片下面显示标题 |
github | 在右上角显示 github 仓库的图标链接 |
styles-sass |
使用 SASS 替换 CSS| |styles-less| 使用 LESS 替换 CSS| |github-buttons| 显示 github 仓库的 star 和 fork 按钮| |sectionx| 分离各个段落,并提供一个展开收起的按钮|
mermaid 基本用法
'''mermaid // ' 改为 `
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
'''
JS Sequence Diagram 基本用法:
'''sequence // ' 改为 `
Title: 标题
A->B: 直线
B-->C: 虚线
C->>D: 箭头
D-->>A: 虚线箭头
'''