1. 导出格式
目前为止,Gitbook 支持如下输出:
- 静态HTML(静态网站)
- PDF格式
- eBook格式
- Mobi 格式
目前常见的电子书格式主要主要有三种(
ePub
,Mobi
,Gitbook
中导出这三种格式都依赖于系统本身提供的ebook-convert
工具支持.
在本系列文章的 Gitbook-介绍和安装详解 已经介绍了怎么安装 ebook-convert
工具,再这里就不多介绍了,接下来将针对上面的几种常见的电子书的导出进行介绍。
2. 基本命令
语法格式:
gitbook build:导出静态网站HTML格式文件
gitbook pdf:导出PDF格式文件
gitbook epub:导出ePub格式文件
gitbook mobi:导出Mobi格式文件
简单示例:
# 1. 生成 `html` 静态网站文件并输出 `debug` 级别日志
$ gitbook build --log=debug
# 2. 生成 `pdf` 文件并输出 `debug` 级别日志
$ gitbook pdf book.pdf --log=debug
# 3. 生成 `epub` 文件并输出 `debug` 级别日志
$ gitbook epub book.epub --log=debug
# 4. 生成 `mobi` 文件并输出 `debug` 级别日志
$ gitbook mobi book.mobi --log=debug
3. 导出书籍为HTML格式的静态网站
Gitbook
默认静态编译就是 HTML 格式的静态网站,默认导出文件到书籍目录的下的 _book
中。
在书籍目录终端中执行 gitbook build
命令就可以将书籍导出到目录 _bo0k
目录中HTML的静态网页HTML文件。
参考示例:
# 静态编译导出HTML静态网站文件,如果需要查看生成日志过程,可以加上--log=debug
$ gitbook build
info: 28 plugins are installed
info: 22 explicitly listed
info: loading plugin "insert-logo"... OK
info: loading plugin "favicon"... OK
info: loading plugin "search-pro"... OK
info: loading plugin "splitter"... OK
info: loading plugin "github"... OK
info: loading plugin "sharing-plus"... OK
info: loading plugin "code"... OK
info: loading plugin "advanced-emoji"... OK
info: loading plugin "emphasize"... OK
info: loading plugin "image-captions"... OK
info: loading plugin "anchor-navigation-expand"... OK
info: loading plugin "alerts"... OK
info: loading plugin "flexible-alerts"... OK
info: loading plugin "auto-scroll-table"... OK
info: loading plugin "lightbox"... OK
info: loading plugin "tbfed-pagefooter"... OK
info: loading plugin "hide-element"... OK
info: loading plugin "prism"... OK
info: loading plugin "chapter-fold"... OK
info: loading plugin "donate"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 38 pages
info: found 26 asset files
warn: "options" property is deprecated, use config.get(key) instead
warn: "options.generator" property is deprecated, use "output.name" instead
warn: "this.generator" property is deprecated, use "this.output.name" instead
warn: "navigation" property is deprecated
warn: "book" property is deprecated, use "this" directly instead
info: >> generation finished with success in 2.8s !
# 简单查看生成的_book目录
$ tree -L 1
.
├── _book
├── book.json
├── node_modules
├── README.md
└── SUMMARY.md
# 简单查看_book目录中的内容
$ cd _book
$ tree -L 1
.
├── gitbook
├── index.html
└── search_plus_index.json
效果预览:
4. 导出书籍为PDF格式文件
相信大家对 PDF
格式的文件应该不会陌生的吧,在实际生活的场景中,PDF 文件也是比较常见的,比如电子发票,公告文档,材料文档,说明文档等等...
接下来就来介绍一下 Gitbook
中将书籍怎么导出成一个PDF格式的文件。在书籍目录终端中执行 git book pdf
命令就可以将书籍导出到书籍目录下的一个名称为 book.pdf
的文件了。
使用示例:
# 将书籍导出到PDF文件,如果需要查看生成日志过程,可以加上--log=debug
$ gitbook pdf
info: 28 plugins are installed
info: 22 explicitly listed
info: loading plugin "insert-logo"... OK
info: loading plugin "favicon"... OK
info: loading plugin "search-pro"... OK
info: loading plugin "splitter"... OK
info: loading plugin "github"... OK
info: loading plugin "sharing-plus"... OK
info: loading plugin "code"... OK
info: loading plugin "advanced-emoji"... OK
info: loading plugin "emphasize"... OK
info: loading plugin "image-captions"... OK
info: loading plugin "anchor-navigation-expand"... OK
info: loading plugin "alerts"... OK
info: loading plugin "flexible-alerts"... OK
info: loading plugin "auto-scroll-table"... OK
info: loading plugin "lightbox"... OK
info: loading plugin "tbfed-pagefooter"... OK
info: loading plugin "hide-element"... OK
info: loading plugin "prism"... OK
info: loading plugin "chapter-fold"... OK
info: loading plugin "donate"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 38 pages
info: found 28 asset files
warn: "options" property is deprecated, use config.get(key) instead
warn: "options.generator" property is deprecated, use "output.name" instead
warn: "this.generator" property is deprecated, use "this.output.name" instead
warn: "navigation" property is deprecated
warn: "book" property is deprecated, use "this" directly instead
info: >> generation finished with success in 11.9s !
info: >> 1 file(s) generated
# 查看生成的book.pdf文件
$ tree -L 1
.
├── _book
├── book.json
├── book.pdf
├── images
├── node_modules
├── README.md
└── SUMMARY.md
效果预览:
PDF格式文件效果图预览5. 导出书籍为ePub格式文件
说起 ePub
文件格式,相信大多数人还是比较不熟悉的,相比较 PDF 格式,ePub 格式在日常生活中使用的场景并没有那么平凡,所以这里简单给大家介绍一下 ePub 格式:
ePub(Electronic Publication的缩写,意为:电子出版),是一个自由的开放标准,属于一种可以“自动重新编排”的内容。
电子出版(Electronic Publishing)是指以数字代码方式将图、文、声、像等信息编辑加工后存储在磁、光、电介质上,信息通过计算机或其他具有类似功能的设备读取使用的一种出版形式。电子出版(elektronisches Publizieren)分成在线电子出版(elektronisches Online-Publizieren)和离线电子出版(elektronisches Offline-Publizieren)两大类型。
通常包括前期策划、素材准备、美术设计、程序编制、后期制作或通过网络发送等环节。可见电子出版以计算机为生产工具,原作的大量复制也是以计算机为核心。这里,定义出版时所必需的编辑改为前期策划、素材准备和美术设计等。因此,与传统意义上的出版相比,电子出版包含了更复杂的劳动。工艺手段和技术含量也更高。
在书籍目录终端中执行 gitbook epub
命令就可以生成一个名称为 book.epub
的文件。
使用示例:
# 将书籍导出到ePub文件,如果需要查看生成日志过程,可以加上--log=debug
$ gitbook epub
info: 28 plugins are installed
info: 22 explicitly listed
info: loading plugin "insert-logo"... OK
info: loading plugin "favicon"... OK
info: loading plugin "search-pro"... OK
info: loading plugin "splitter"... OK
info: loading plugin "github"... OK
info: loading plugin "sharing-plus"... OK
info: loading plugin "code"... OK
info: loading plugin "advanced-emoji"... OK
info: loading plugin "emphasize"... OK
info: loading plugin "image-captions"... OK
info: loading plugin "anchor-navigation-expand"... OK
info: loading plugin "alerts"... OK
info: loading plugin "flexible-alerts"... OK
info: loading plugin "auto-scroll-table"... OK
info: loading plugin "lightbox"... OK
info: loading plugin "tbfed-pagefooter"... OK
info: loading plugin "hide-element"... OK
info: loading plugin "prism"... OK
info: loading plugin "chapter-fold"... OK
info: loading plugin "donate"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 38 pages
info: found 29 asset files
warn: "options" property is deprecated, use config.get(key) instead
warn: "options.generator" property is deprecated, use "output.name" instead
warn: "this.generator" property is deprecated, use "this.output.name" instead
warn: "navigation" property is deprecated
warn: "book" property is deprecated, use "this" directly instead
info: >> generation finished with success in 4.5s !
info: >> 1 file(s) generated
# 查看生成的book.epub文件
$ tree -L 1
.
├── _book
├── book.epub
├── book.json
├── images
├── node_modules
├── README.md
└── SUMMARY.md
效果预览:
6. 导出书籍为Mobi格式文件
Mobi是什么文件格式?
mobi
格式是一种广泛流行于网络的电子书格式,是亚马逊电子书格式,可以用亚马逊电子设备打开观看,也可用电脑打开,但需要使用特定的工具才能打开。
在书籍目录终端中执行 gitbook mobi
命令就可以生成一个名称为 book.mobi
的文件。
使用示例:
# 将书籍导出到Mobi文件,如果需要查看生成日志过程,可以加上--log=debug
$ gitbook mobi
info: 28 plugins are installed
info: 22 explicitly listed
info: loading plugin "insert-logo"... OK
info: loading plugin "favicon"... OK
info: loading plugin "search-pro"... OK
info: loading plugin "splitter"... OK
info: loading plugin "github"... OK
info: loading plugin "sharing-plus"... OK
info: loading plugin "code"... OK
info: loading plugin "advanced-emoji"... OK
info: loading plugin "emphasize"... OK
info: loading plugin "image-captions"... OK
info: loading plugin "anchor-navigation-expand"... OK
info: loading plugin "alerts"... OK
info: loading plugin "flexible-alerts"... OK
info: loading plugin "auto-scroll-table"... OK
info: loading plugin "lightbox"... OK
info: loading plugin "tbfed-pagefooter"... OK
info: loading plugin "hide-element"... OK
info: loading plugin "prism"... OK
info: loading plugin "chapter-fold"... OK
info: loading plugin "donate"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 38 pages
info: found 31 asset files
warn: "options" property is deprecated, use config.get(key) instead
warn: "options.generator" property is deprecated, use "output.name" instead
warn: "this.generator" property is deprecated, use "this.output.name" instead
warn: "navigation" property is deprecated
warn: "book" property is deprecated, use "this" directly instead
info: >> generation finished with success in 6.0s !
info: >> 1 file(s) generated
# 查看生成的book.mobi文件
$ tree -L 1
.
├── _book
├── book.json
├── book.mobi
├── node_modules
├── README.md
└── SUMMARY.md
预览效果:
7. 结束
关于使用 Gitbook
导出各种格式电子书籍的介绍已经结束了,在我们日常使用中其实大多数情况都是导出静态 HTML
和 PDF
这两种常用的格式,目前的设备中支持这两种文件格式的软件比较多。
网友评论