Learn to walk before you run

GitBook的使用

2020.01.15

安装

  1. 安装Node.js
node -v
  1. 安装GitBook
npm install gitbook-cli -g

验证

gitbook -V

35729 4000

使用

1.创建项目

gitbook init

2.启动服务或直接编译成静态页面

gitbook serve
gitbook build

注:服务默认端口:4000和35729

3.目录结构

.
├── book.json
├── README.md
├── SUMMARY.md
├── chapter-1/
├── README.md
 |   └── something.md
└── chapter-2/
    ├── README.md
    └── something.md

4.目录SUMMARY.md 格式1

# Summary
* [Introduction](README.md)
* [Part I](part1/README.md)
    * [Writing is nice](part1/writing.md)
    * [GitBook is nice](part1/gitbook.md)* [Part II](part2/README.md)
    * [We love feedback](part2/feedback_please.md)
    * [Better tools for authors](part2/better_tools.md)

格式2

# Summary
### Part I
* [Introduction](README.md)
* [Writing is nice](part1/writing.md)
* [GitBook is nice](part1/gitbook.md)

### Part II
* [We love feedback](part2/feedback_please.md)
* [Better tools for authors](part2/better_tools.md)

---
* [Last part without title](part3/title.md)

5.自定义配置book.json文件

{
    "title": "Blankj's Glory",
    "author": "Blankj",
    "description": "select * from learn",
    "language": "zh-hans",
    "gitbook": "3.2.3",
    "styles": {
        "website": "./styles/website.css"
    },
    "structure": {
        "readme": "README.md"
    },
    "links": {
        "sidebar": {
            "我的狗窝": "https://blankj.com"
        }
    },
    "plugins": [
        "-sharing",
        "splitter",
        "expandable-chapters-small",
        "anchors",
        "github",
        "github-buttons",
        "donate",
        "sharing-plus",
        "anchor-navigation-ex",
        "favicon"
    ],
    "pluginsConfig": {
        "github": {
            "url": "https://github.com/Blankj"
        },
        "github-buttons": {
            "buttons": [{
                "user": "Blankj",
                "repo": "glory",
                "type": "star",
                "size": "small",
                "count": true
                }
            ]
        },
        "donate": {
            "alipay": "./source/images/donate.png",
            "title": "",
            "button": "赞赏",
            "alipayText": " "
        },
        "sharing": {
            "douban": false,
            "facebook": false,
            "google": false,
            "hatenaBookmark": false,
            "instapaper": false,
            "line": false,
            "linkedin": false,
            "messenger": false,
            "pocket": false,
            "qq": false,
            "qzone": false,
            "stumbleupon": false,
            "twitter": false,
            "viber": false,
            "vk": false,
            "weibo": false,
            "whatsapp": false,
            "all": [
                "google", "facebook", "weibo", "twitter",
                "qq", "qzone", "linkedin", "pocket"
            ]
        },
        "anchor-navigation-ex": {
            "showLevel": false
        },
        "favicon":{
            "shortcut": "./source/images/favicon.jpg",
            "bookmark": "./source/images/favicon.jpg",
            "appleTouch": "./source/images/apple-touch-icon.jpg",
            "appleTouchMore": {
                "120x120": "./source/images/apple-touch-icon.jpg",
                "180x180": "./source/images/apple-touch-icon.jpg"
            }
        }
    }}

简单配置

{
    "author": "VictorXu",
    "description": "stay hungry stay foolish",
    "gitbook": "3.2.3",
    "language": "zh-hans",
    "links": {
        "sidebar": {
            "我的主页": "https://www.appgole.com"
        }
    },
    "plugins": [
        "-sharing",
        "splitter",
        "expandable-chapters-small",
        "anchors",
        "-donate",
        "github",
        "github-buttons",
        "-sharing-plus",
        "anchor-navigation-ex"
    ],
    "pluginsConfig": {
        "anchor-navigation-ex": {
            "showLevel": false
        },
        "github": {
            "url": "https://github.com/tsdking"
        },
        "github-buttons": {
            "buttons": [
                {
                    "count": true,
                    "repo": "androidannotations",
                    "size": "small",
                    "type": "star",
                    "user": "tsdking"
                }
            ]
        },
        "sharing": {
            "all": [
                "google",
                "facebook",
                "weibo",
                "twitter",
                "qq",
                "qzone",
                "linkedin",
                "pocket"
            ],
            "douban": false,
            "facebook": false,
            "google": false,
            "hatenaBookmark": false,
            "instapaper": false,
            "line": false,
            "linkedin": false,
            "messenger": false,
            "pocket": false,
            "qq": false,
            "qzone": false,
            "stumbleupon": false,
            "twitter": false,
            "viber": false,
            "vk": false,
            "weibo": false,
            "whatsapp": false
        }
    },
    "structure": {
        "readme": "README.md"
    },
    "styles": {
        "website": "./styles/website.css"
    },
    "title": "VictorXu's Notes"
}

安装及使用中遇到的问题解决FAQ

1.GitBook运行报错 - no such file or directory

找到这个文件:xxx\lib\output\website\copyPluginAssets.js 把文件中confirm: true全部修改为confirm: false