須要注意的是:用戶首先須要安裝 nodejs,以便可以使用 npm 來安裝 gitbook。css
npm install gitbook -g //查看安裝的版本 gitbook -V
//建立目錄 mkdir pfinal-club //初始化圖書 gitbook init
使用下面的命令,會在項目的目錄下生成一個 _book
目錄,裏面的內容爲靜態站點的資源文件:html
gitbook build
使用下列命令會運行一個 web 服務, 經過 http://localhost:4000/
能夠預覽書籍node
gitbook serve
GitBook使用簡單的目錄結構。在 SUMMARY (即 SUMMARY.md
文件)中列出的全部 Markdown / Asciidoc 文件將被轉換爲 HTML。多語言書籍結構略有不一樣。git
一個基本的 GitBook 電子書結構一般以下:github
. ├── book.json ├── README.md ├── SUMMARY.md ├── chapter-1/ | ├── README.md | └── something.md └── chapter-2/ ├── README.md └── something.md
文件說明:web
文件 | 描述 |
---|---|
book.json |
配置數據 (optional) |
README.md |
電子書的前言或簡介 (required) |
SUMMARY.md |
電子書目錄 (optional) |
GLOSSARY.md |
詞彙/註釋術語列表 (optional) |
GitBook 使用 SUMMARY.md
文件來定義本書的章節和子章節的結構。 SUMMARY.md
文件用於生成本書的目錄。npm
SUMMARY.md
的格式是一個連接列表。連接的標題將做爲章節的標題,連接的目標是該章節文件的路徑。json
向父章節添加嵌套列表將建立子章節。服務器
示例:微信
# Summary * [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)
部分
目錄能夠分爲以標題或水平線 ----
分隔的部分:
# Summary ### Part I * [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)
Parts 只是章節組,沒有專用頁面,但根據主題,它將在導航中顯示。
配置在 book.json
文件中設置。下面是一個標準的配置文件。
須要執行 gitbook install
安裝配置文件中的插件
"title": "PFinal社區", "description": "PFinal社區簡介", "author": "PF南丞", "output.name": "site", "language": "zh-hans", "gitbook": "3.2.3", "root": ".", "structure": { "readme": "README.md" }, "links": { "sidebar": { "PFinal社區": "http://www.pfinalClub.com" } }, "plugins": [ "-lunr", "-search", "-highlight", "-livereload", "search-plus@^0.0.11", "simple-page-toc@^0.1.1", "github@^2.0.0", "github-buttons@2.1.0", "edit-link@^2.0.2", "disqus@^0.1.0", "prism@^2.1.0", "prism-themes@^0.0.2", "advanced-emoji@^0.2.1", "anchors@^0.7.1", "include-codeblock@^3.0.2", "ace@^0.3.2", "emphasize@^1.1.0", "katex@^1.1.3", "splitter@^0.0.8", "mermaid-gb3@2.1.0", "tbfed-pagefooter@^0.0.1", "expandable-chapters-small@^0.1.7", "sectionx@^3.1.0", "donate@^1.0.2", "local-video@^1.0.1", "sitemap-general@^0.1.1", "anchor-navigation-ex@0.1.8", "favicon@^0.0.2", "todo@^0.1.3", "3-ba@^0.9.0", "terminal@^0.3.2", "alerts@^0.2.0", "include-csv@^0.1.0", "puml@^1.0.1", "musicxml@^1.0.2", "klipse@^1.2.0", "versions-select@^0.1.1", "rss@^3.0.2", "-sharing", "sharing-plus@^0.0.2", "graph@^0.1.0", "chart@^0.2.0" ], "pluginsConfig": { "theme-default": { "showLevel": true }, "disqus": { "shortName": "PFinal" }, "prism": { "css": [ "prism-themes/themes/prism-base16-ateliersulphurpool.light.css" ] }, "github": { "url": "https://github.com/pfinal/book" }, "github-buttons": { "repo": "pfinal/book", "types": [ "star" ], "size": "small" }, "include-codeblock": { "template": "ace", "unindent": true, "edit": true }, "sharing": { "douban": false, "hatenaBookmark": false, "instapaper": false, "line": false, "linkedin": false, "messenger": false, "pocket": false, "qq": true, "qzone": true, "stumbleupon": false, "twitter": false, "viber": false, "vk": false, "weibo": true, "whatsapp": false, "all": [ "douban", "twitter", "line","facebook" ] }, "tbfed-pagefooter": { "copyright": "Copyright © <a href='http://pfinalClub.com'>pfinalClub.com</a> 2018", "modify_label": "該文件修訂時間:", "modify_format": "YYYY-MM-DD HH:mm:ss" }, "3-ba": { "token": "ff100361cdce95dd4c8fb96b4009f7bc" }, "donate": { "wechat": "http://www.pfinalclub.com/wechat.JPG", "alipay": "http://www.pfinalclub.com/alipay.JPG", "title": "", "button": "賞", "alipayText": "支付寶打賞", "wechatText": "微信打賞" }, "simple-page-toc": { "maxDepth": 3, "skipFirstH1": true }, "edit-link": { "base": "https://github.com/pfinal/book/edit/master", "label": "Edit This Page" }, "sitemap-general": { "prefix": "http://gitbook.pfinal.com" }, "anchor-navigation-ex": { "isRewritePageTitle": false, "tocLevel1Icon": "fa fa-hand-o-right", "tocLevel2Icon": "fa fa-hand-o-right", "tocLevel3Icon": "fa fa-hand-o-right" }, "sectionx": { "tag": "b" }, "favicon": { "shortcut": "favicon.ico", "bookmark": "favicon.ico" }, "terminal": { "copyButtons": true, "fade": false, "style": "flat" }, "rss": { "title": "PFinal社區", "description": "PFinal社區簡介", "author": "PF南丞", "categories": [ "gitbook" ] } } }
本篇文章由一文多發平臺ArtiPub自動發佈