Skip to content

Latest commit

 

History

History
331 lines (254 loc) · 7.05 KB

GitbookStructure.md

File metadata and controls

331 lines (254 loc) · 7.05 KB

Gitbook 配置

全局配置

基础的类似 title、author、author、description 之类的就不讲了,这里主要介绍一下这个项目里的一些插件的用法。

structure

Gitbook 默认需要有一个 Readme 文件,如果需要使用其他的 md 文件作为 Gitbook 的 Readme 文件,可以在 structure 里指定。

 "structure": {
    "readme": "Introduction.md"
  },

links

在左侧导航栏添加链接信息

"links" : {
    "sidebar" : {
        "Home" : "https://www.baidu.com"
    }
}

plugins 插件列表

plugins 参数为数组格式,我们只需要把需要用到插件名添加进去就可以了,其中 "-" 符号代表移除这个插件。

"plugins": [
    "-lunr",
    "-search",
    "-highlight",
    "-livereload",
    "-sharing",
    "search-plus"
]

Gitbook 默认自带有 5 个插件:

  • highlight: 代码高亮
  • search: 导航栏查询功能(不支持中文)
  • sharing:右上角分享功能
  • font-settings:字体设置(最上方的"A"符号)
  • livereload:为 GitBook 实时重新加载

比如search-plus支持中文搜索, 需要将默认的 search 和 lunr 插件去掉。

pluginsConfig 插件属性配置

在这个参数里配置插件的属性

例如配置 edit-link 的属性:

"pluginsConfig": {
    "edit-link": {
      "base": "https://github.com/wswdavid/Study_Record/blob/master",
      "label": "Edit This Page"
    }
}

一些实用的插件

advanced-emoji

支持 emoji 表情

Emoji Cheat Sheet

{
  "plugins": ["advanced-emoji"]
}

back-to-top-button

回到顶部按钮

{
  "plugins": ["back-to-top-button"]
}

popup

点击图片,打开新的页面查看大图

{
  "plugins": ["popup"]
}

hide-element

可以隐藏不想看到的元素,比如导航栏中Published by GitBook

hide-element是通过 HTML 元素的 class 名字来查找要隐藏的元素,想要隐藏元素找到元素的样式类名加到插件配置里面就可以隐藏元素了。

{
  "plugins": ["hide-element"],
  "pluginsConfig": {
    "hide-element": {
      "elements": [".gitbook-link"]
    }
  }
}

emphasize

为文字加上底色

{
  "plugins": ["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 {% 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 %}

tbfed-pagefooter

页面添加页脚、版权信息

{
  "plugins": ["tbfed-pagefooter"],
  "pluginsConfig": {
    "tbfed-pagefooter": {
      "copyright": "<a href='http://www.beian.miit.gov.cn'>粤ICP备19162056-1号</a> Copyright © wswdavid 2020",
      "modify_label": "该文件修订时间:",
      "modify_format": "YYYY-MM-DD HH:mm:ss"
    }
  }
}

sectionx

用于将页面分成多个部分,并添加按钮以允许读者控制每个部分的可见性。

官网地址

示例地址

{
  "plugins": ["sectionx"]
}

具体使用方法请参考官网,这里介绍一个简单的用例。

<!--sec data-title="标题2" data-id="section0" data-show=true ces-->

内容部分 2;

<!--endsec-->

内容部分 2;

page-toc-button

悬浮目录,可以通过 pluginsConfig 定制配置

{
  "plugins": ["page-toc-button"],
  "pluginsConfig": {
    "page-toc-button": {
      "maxTocDepth": 2,
      "minTocSize": 2
    }
  }
}

flexible-alerts

将块引用转换为漂亮的警报。可以在全局和警报特定级别配置外观.此外,还可以配置自己的警报类型。用法可以参考Github 官网

{
  "plugins": ["flexible-alerts"]
}

示例

> [!WARNING]
> 这是一个简单的 WARNING 类型的使用,所有的属性都是默认值。

---

> [!TIP|style:flat|label:My own heading|iconVisibility:hidden]
> An alert of type 'tip' using alert specific style 'flat' which overrides global style 'callout'.
> In addition, this alert uses an own heading and hides specific icon.

Warning

这是一个简单的 WARNING 类型的使用,所有的属性都是默认值。


[!TIP|style:flat|label:My own heading|iconVisibility:hidden] An alert of type 'tip' using alert specific style 'flat' which overrides global style 'callout'. In addition, this alert uses an own heading and hides specific icon.

最后是本项目所使用的 book.json 文件,点击以下查看。

{
  "title": "Study Record",
  "description": "A website generated by Gitbook for recording study notes",
  "author": "wswdavid",
  "language": "zh-hans",
  "gitbook": "3.2.3",
  "root": ".",
  "structure": {
    "readme": "Introduction.md"
  },
  "plugins": [
    "-lunr",
    "-search",
    "-highlight",
    "-livereload",
    "-sharing",
    "search-plus",
    "edit-link",
    "tbfed-pagefooter",
    "hide-element",
    "popup",
    "flexible-alerts",
    "copy-code-button",
    "code",
    "katex",
    "emphasize",
    "back-to-top-button",
    "multipart",
    "prism",
    "prism-themes",
    "sectionx",
    "expandable-chapters-small",
    "splitter",
    "advanced-emoji",
    "page-toc-button",
    "include-codeblock",
    "ace"
  ],
  "pluginsConfig": {
    "prism": {
      "css": ["prism-themes/themes/prism-atom-dark.css"]
    },
    "hide-element": {
      "elements": [".gitbook-link"]
    },
    "edit-link": {
      "base": "https://github.com/wswdavid/Study_Record/blob/master",
      "label": "Edit This Page"
    },
    "tbfed-pagefooter": {
      "copyright": "<a href='http://www.beian.miit.gov.cn'>粤ICP备19162056-1号</a> Copyright © wswdavid 2020",
      "modify_label": "该文件修订时间:",
      "modify_format": "YYYY-MM-DD HH:mm:ss"
    },
    "page-toc-button": {
      "maxTocDepth": 2,
      "minTocSize": 2
    },
    "include-codeblock": {
      "template": "ace",
      "unindent": true,
      "edit": true
    }
  },
  "links": {
    "sidebar": {
      "Github URL": "https://github.com/wswdavid/Study_Record"
    }
  },
  "links": {
    "sidebar": {
      "Github URL": "https://github.com/wswdavid/Study_Record"
    }
  }
}