GitBook相關配置及優化

一、GitBook配置說明

1.一、目錄結構
├── book.json
├── README.md
├── SUMMARY.md
├── chapter-1/
|    ├── README.md
|    ├── something.md
├── chapter-2/
|    ├── README.md
1.二、GitBook 特殊文件的功能:
文件名 描述
book.json 配置數據 (optional)
README.md 電子書的前言或簡介 (required)
SUMMARY.md 電子書目錄 (optional)
GLOSSARY.md 詞彙/註釋術語列表 (optional)
1.三、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.四、Gitbook 默認帶有 5 個插件:
  • highlight - 語法高亮插件search - 搜索插件sharing - 分享插件font-settings - 字體設置插件livereload - 熱加載插件
1.五、去除自帶插件

能夠在插件名稱前面加 -css

"plugins": [
  "-search"
]

Tips:添加插件後要進行安裝 gitbook installhtml

1.六、設置PDF輸出格式
變量 描述
pdf.pageNumbers 是否添加頁碼,默認是true
pdf.fontSize 字體大小,默認是12
pdf.fontFamily 字體,默認字體是Arial
pdf.paperSize Paper size, options are a0,a1,a2,a3,a4,a5,a6,b0,b1,b2,b3,b4,b5,b6,legal,letter(default is a4)
pdf.margin.top Top margin (default is 56)
pdf.margin.bottom Bottom margin (default is 56)
pdf.margin.right Right margin (default is 62)
pdf.margin.left Left margin (default is 62)

二、GitBook生成電子書

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

三、使用gitbook-convert

說明:把 docxxmlhtmlodt文檔轉成 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]

四、GitBook插件列表

五、博主示例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 installnode

相關文章
相關標籤/搜索