须要注意的是:用户首先须要安装 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自动发布