gitbook 配置与插件

自定义配置与插件是在 book.json 配置的

{
    "variables": {
        "myVariable": "Hello World"
    }
}

上面给出的代码,配置了一个全局模板变量 myVariable,我们可以通过 {{ book.myVariable }} 来调用改变量

Plugin

插件可以在这里下载安装和配置

{
    "plugins": ["myPlugin", "anotherPlugin"]
}

设置好插件后,需要运行命令 gitbook install 来安装插件

插件 gitbook-plugin-search-pro

该插件支持中文搜索,在安装过程中可能会报 node-gyp rebuild 错误,解决方法,先删除已安装的插件, 运行命令 npm install nodejieba,再 gitbook install

Emphasize 给文字加背景色

例子

This text is {% em %}highlighted !{% endem %}

This text is {% em %}highlighted with **markdown**!{% endem %}

This text is {% em type="green" %}highlighted in green!{% endem %}

This text is {% em type="red" %}highlighted in red!{% endem %}

This text is {% em color="#ff0000" %}highlighted with a custom color!{% endem %}

预览效果

This text is highlighted !

This text is highlighted with markdown!

This text is highlighted in green!

This text is highlighted in red!

This text is highlighted with a custom color!

splitter 侧边栏的宽度可以自由调节

include-codeblock 代码块包含引入的文件

使用代码块格式显示所包含文件的内容,该文件必须存在,否则会报错,可以截取显示部分包含内容

例子

book.json

{
  "language" : "zh-hans",
  "plugins": [
      "disqus",
      "-search",

tbfed-pagefooter

为页面添加底部页脚

"plugins": [
   "tbfed-pagefooter"
],
"pluginsConfig": {
    "tbfed-pagefooter": {
        "copyright":"Copyright &copy 2016",
        "modify_label": "最后修改时间:",
        "modify_format": "YYYY-MM-DD HH:mm:ss"
    }
}

toggle-chapters

左侧目录可以折叠

"plugins": ["toggle-chapters"]

sectionx

页面分块显示插件

"plugins": ["sectionx"]

例子

gitbook-plugin-sectionx

Introduction

This page is implemented using the two plugins developed by me: gitbook-plugin-sectionx, please check the Github repo for the plugin.

The source code for this page is available here.

Example

This is a section that is by default visible (with data-show=true). You can toggle this with the button in the title. The next section is hidden by default, you can add a custom button to toggle it (see GitHub for the syntax).

源代码看这里 https://github.com/ymcatar/gitbook-test

该插件的作者还实现了一些其他插件,详情点击这里 https://github.com/ymcatar

baidu

百度统计插件

你需要在百度统计中添加一个 token,比如:c12134efe8099063bacebecb25df3b7d 然后配置

{
    "plugin": ["baidu"],
    "pluginsConfig": {
        "baidu": {
            "token": "YOUR TOKEN"
        }
    }
}

分享

可以这样配置

"sharing": {
    "weibo": true,
    "facebook": true,
    "twitter": true,
    "google": false,
    "instapaper": false,
    "vk": false,
    "all": [
        "facebook", "google", "twitter",
            "weibo", "instapaper"
    ]
}

代码高亮

gitbook 中代码高亮是基于 highlightjs实现的

参考资料

Copyright © 2015 all right reserved,powered by Gitbook最后修改时间: 2016-02-25 22:57:06