gitbook安装与使用

Gitbook可以做什么?

  1. 以markdown书写结构性的文章,并以Web形式呈现
  2. 支持搜索
  3. 支持主题,页面自适应。
  4. 支持插件,如评论等
  5. 有商业化的gitbook.com提供支持

由于其结构性,使得站点看起来就是完整的一部书。

这里主要讲gitbook的本地安装和使用。

安装

前提先安装好node和npm。

npm install gitbook-cli -g 

初始化

gitbook init

该命令会生成README.mdSUMMARY.md两个文件,编辑 SUMMARY.md,结构如下

# Summary

* [Introduction](README.md)
* [Chapter1](chapter1/README.md)
    * [Section1.1](chapter1/section1.1.md)
        * [Section1.1.1](chapter1/section1/section1.1.1.md)
        * [Section1.1.2](chapter1/section2/section1.1.2.md)
            * [Section1.1.2.1](chapter1/section1/sub2/section1.1.1.1.md)
            * [Section1.1.2.2](chapter1/section1/sub2/section1.1.1.2.md)
    * [Section1.2](chapter1/section1.2.md)
* [Chapter2](chapter2/README.md)

支此多级结构,每下一级,多4个空格。

  1. 再次执行上面的命令,gitbook会自动生成相应的目录结构。

编辑MD文件内容

本地运行

gitbook server

构建静态

gitbook build

注意点

  1. {{}}是gitbook的模板语言,所以如果文档中出现大括号,需要转义,如下
{% raw %}{{ }}{% endraw %}
  1. 如果文章过多,可能会造成search_index.json文件过大造成加载慢的问题。

Leave a Comment

豫ICP备19001387号-1