Gitbook詳解(六)-導出電子書詳解


1. 導出格式

目前為止,Gitbook 支持如下輸出:

  • 靜態HTML(靜態網站)
  • PDF格式
  • eBook格式
  • Mobi 格式

目前常見的電子書格式主要主要有三種(ePub, Mobi, PDF),在 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

效果預覽:
靜態HTML文件效果預覽圖

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

效果預覽:
ePub格式文件效果圖預覽

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

預覽效果:
Mobi格式文件效果圖預覽

7. 結束

關於使用 Gitbook 導出各種格式電子書籍的介紹已經結束了,在我們日常使用中其實大多數情況都是導出靜態 HTMLPDF 這兩種常用的格式,目前的設備中支持這兩種文件格式的軟件比較多。

>>> 系列文章快捷導航:

  1. Gitbook詳解(一)-介紹和安裝詳解
  2. Gitbook詳解(二)-命令行的使用
  3. Gitbook詳解(三)-目錄結構詳解
  4. Gitbook詳解(四)-配置和說明詳解
  5. Gitbook詳解(五)-插件的配置和使用詳解
  6. Gitbook詳解(六)-導出電子書詳解
  7. Gitbook詳解(七)-Markdown編輯器推薦
  8. Gitbook詳解(八)-發布書籍


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM