GitBook相关配置及优化

1、GitBook配置说明

1.1、目录结构
├── book.json
├── README.md
├── SUMMARY.md
├── chapter-1/
|    ├── README.md
|    ├── something.md
├── chapter-2/
|    ├── README.md
1.2、GitBook 特殊文件的功能:
文件名描述
book.json配置数据 (optional)
README.md电子书的前言或简介 (required)
SUMMARY.md电子书目录 (optional)
GLOSSARY.md词汇/注释术语列表 (optional)
1.3、book.json的配置说明
变量描述
root包含所有图书文件的根文件夹的路径,除了 book.json
structure指定自述文件,摘要,词汇表等的路径
title您的书名,默认值是从 README 中提取出来的。在 GitBook.com 上,这个字段是预填的。
description您的书籍的描述,默认值是从 README 中提取出来的。在 GitBook.com 上,这个字段是预填的。
author作者名。在GitBook.com上,这个字段是预填的。
isbn国际标准书号 ISBN
language本书的语言类型 —— ISO code 。默认值是 en
direction文本阅读顺序。可以是 rtl (从右向左)或 ltr (从左向右),默认值依赖于 language 的值。
gitbook应该使用的GitBook版本,并接受类似于 >=3.0.0 的条件。
links在左侧导航栏添加链接信息
plugins要加载的插件列表(官网插件列表)
pluginsConfig插件的配置
1.4、Gitbook 默认带有 5 个插件:
  • highlight - 语法高亮插件search - 搜索插件sharing - 分享插件font-settings - 字体设置插件livereload - 热加载插件
1.5、去除自带插件

可以在插件名称前面加 -

"plugins": [
  "-search"
]

Tips:添加插件后要进行安装 gitbook install

1.6、设置PDF输出格式
变量描述
pdf.pageNumbers是否添加页码,默认是true
pdf.fontSize字体大小,默认是12
pdf.fontFamily字体,默认字体是Arial
pdf.paperSizePaper size, options are a0,a1,a2,a3,a4,a5,a6,b0,b1,b2,b3,b4,b5,b6,legal,letter(default is a4)
pdf.margin.topTop margin (default is 56)
pdf.margin.bottomBottom margin (default is 56)
pdf.margin.rightRight margin (default is 62)
pdf.margin.leftLeft margin (default is 62)

2、GitBook生成电子书

--- 生成PDF文件
# gitbook pdf ./ ./mybook.pdf
--- 生成ePub文件
# gitbook epub ./ ./mybook.epub
--- 生成Mobi文件
# gitbook mobi ./ ./mybook.mobi

3、使用gitbook-convert

说明:把
docx
xml
html
odt文档转成
GitBook

# npm install gitbook-convert -g
--- 如果需要做软链
# ln -s /usr/local/node-v8.11.2-linux-x64/bin/gitbook-convert /usr/local/bin/gitbook-convert
--- 如何使用
# gitbook-convert [options] <file> [export-directory]

4、GitBook插件列表

5、博主示例book.json配置

{
    "gitbook": "3.x.x",
    "plugins": ["favicon", "yahei", "github", "autotheme", "-lunr", "-search",
        "search-plus", "prism", "-highlight", "github-buttons", "splitter",
        "-sharing", "sharing-plus", "tbfed-pagefooter", "expandable-chapters-small",
        "book-summary-scroll-position-saver", "ga", "baidu", "donate",
        "anchors", "anchor-navigation-ex", "sitemap-general",
        "copy-code-button", "mygitalk", "multipart"
    ],
    "pluginsConfig": {
        "theme-default": {
            "showLevel": true
        },
        "fontSettings": {
            "family": "serif",
            "size": 2
        },
        "github": {
            "url": "https://github.com/JoeyBling"
        },
        "autotheme": {
            "white": [9, 10, 11, 12, 13, 14, 15, 16, 17],
            "sepia": [6, 7, 8, 18, 19],
            "night": [20, 21, 22, 23, 0, 1, 2, 3, 4, 5]
        },
        "prism": {
            "css": [
                "prismjs/themes/prism-tomorrow.css"
            ]
        },
        "github-buttons": {
            "buttons": [{
                "user": "JoeyBling",
                "repo": "myBook",
                "type": "star",
                "size": "small",
                "count": true
            }]
        },
        "sharing": {
            "douban": false,
            "facebook": false,
            "google": true,
            "hatenaBookmark": false,
            "instapaper": false,
            "line": true,
            "linkedin": true,
            "messenger": false,
            "pocket": false,
            "qq": false,
            "qzone": true,
            "stumbleupon": false,
            "twitter": false,
            "viber": false,
            "vk": false,
            "weibo": true,
            "whatsapp": false,
            "all": [
                "facebook", "google", "twitter",
                "weibo", "instapaper", "linkedin",
                "pocket", "stumbleupon"
            ]
        },
        "tbfed-pagefooter": {
            "copyright": "Copyright &copy <a href='https://zhousiwei.gitee.io' target='_blank'>試毅-思伟</a> 2019",
            "modify_label": "修订时间:",
            "modify_format": "YYYY-MM-DD HH:mm:ss"
        },
        "ga": {
            "token": "UA-142790104-1"
        },
        "baidu": {
            "token": "f1f256f18b7899e11647d6ec1f3ded2f"
        },
        "donate": {
            "wechat": "/assets/weixin.png",
            "alipay": "/assets/alipay.jpeg",
            "title": "",
            "button": "赏",
            "alipayText": "支付宝打赏",
            "wechatText": "微信打赏"
        },
        "anchor-navigation-ex": {
            "showLevel": true,
            "associatedWithSummary": false,
            "printLog": false,
            "multipleH1": true,
            "mode": "float",
            "showGoTop": true,
            "float": {
                "floatIcon": "fa fa-navicon",
                "showLevelIcon": false,
                "level1Icon": "fa fa-hand-o-right",
                "level2Icon": "fa fa-hand-o-right",
                "level3Icon": "fa fa-hand-o-right"
            },
            "pageTop": {
                "showLevelIcon": false,
                "level1Icon": "fa fa-hand-o-right",
                "level2Icon": "fa fa-hand-o-right",
                "level3Icon": "fa fa-hand-o-right"
            }
        },
        "sitemap-general": {
            "prefix": "https://zhousiwei.gitee.io/myBook/"
        },
        "favicon": {
            "shortcut": "/assets/images/favicon.ico",
            "bookmark": "/assets/images/favicon.ico",
            "appleTouch": "/assets/images/apple-touch-icon.png",
            "appleTouchMore": {
                "120x120": "/assets/images/apple-touch-icon-120x120.png",
                "180x180": "/assets/images/apple-touch-icon-180x180.png"
            }
        },
        "mygitalk": {
            "clientID": "608e351b48e4d0a3a528",
            "clientSecret": "***加密***",
            "repo": "myBook",
            "owner": "JoeyBling",
            "admin": ["JoeyBling"],
            "distractionFreeMode": false
        }
    },
    "pdf": {
        "pageNumbers": true,
        "fontFamily": "Arial",
        "fontSize": 12,
        "paperSize": "a4",
        "margin": {
            "right": 62,
            "left": 62,
            "top": 56,
            "bottom": 56
        }
    },
    "title": "試毅-思伟_开源项目",
    "description": "試毅-思伟_开源项目",
    "author": "試毅-思伟",
    "language": "zh-hans",
    "root": ".",
    "structure": {
        "readme": "introduction.md"
    },
    "links": {
        "sidebar": {
            "GitHub": "https://github.com/JoeyBling",
            "个人博客": "https://zhousiwei.gitee.io"
        }
    }
}

Tips:添加插件后要进行安装 gitbook install

    原文作者:試毅_思伟
    原文地址: https://segmentfault.com/a/1190000019664545
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞