Centos 7 下 GitBook 的安裝與使用

https://www.jianshu.com/p/a78e3dda4d87

安裝 Node.js

wget https://nodejs.org/dist/v5.4.1/node-v5.4.1.tar.gz
tar zxvf node-v5.4.1.tar.gz
cd node-v5.4.1
./configure
sudo make
sudo make install

查看 node.js 是否安裝成功

node -v
  • 執行 ./configure 錯誤:WARNING: failed to autodetect C++ compiler version (CXX=g++)

需要安裝 gcc

 sudo yum install gcc-c++

安裝 GitBook

npm install gitbook-cli -g

gitbook 初始化

gitbook --version 
  • 執行 gitbook --version 錯誤:Error: Cannot find module 'config-chain'

    • cannot find module 模塊, 安裝該模塊即可
npm install -g config-chain

創建電子書項目

mkdir book
cd book
gitbook init

創建好的項目目錄中包含以下文件

ovirt-branding.md  README.md  SUMMARY.md
  1. README.md,簡單的電子書介紹。
# 簡介

這是使用 GitBook 製作的電子書。
  1. SUMMARY.md,電子書的導航目錄文件。
# Summary

* [簡介](README.md)
* [第一章](section1/README.md)
* [第二章](section2/README.md)
  • 子章節,使用 Tab 縮進實現(最多支持三級標題)。
# Summary

* [第一章](section1/README.md)
    * [第一節](section1/example1.md)
    * [第二節](section1/example2.md)
* [第二章](section2/README.md)
    * [第一節](section2/example1.md)
  1. Glossary.md,電子書內容中需要解釋的詞彙可在此文件中定義。詞彙表會被放在電子書末尾。
# 電子書
電子書是指將文字、圖片、聲音、影像等訊息內容數字化的出版物和植入或下載數字化文字、圖片、聲音、影像等訊息內容的集存儲和顯示終端於一體的手持閱讀器。
  1. book.json,電子書的配置文件。
{
    "title": "我的第一本電子書",
    "description": "用 GitBook 製作的第一本電子書!",
    "isbn": "978-3-16-148410-0",
    "language": "zh-tw",
    "direction": "ltr"
}
  1. 普通章節.md
  • 每一個普通章節,都需要在 SUMMARY.md 中添加記錄。
  1. 電子書封面圖片
  • 建議封面圖片的尺寸爲 1800*2360 像素。
  • 建議沒有邊框。
  • 建議清晰可見的書本標題。
  • 建議任何重要的文字在小版本中應該可見。
  • 圖片的格式爲 jpg 格式。把圖片重命名爲 cover.jpg 放到電子書項目。

創建完成電子書,進行預覽

gitbook serve

構建

  1. 生成 html 文檔。
gitbook build
  1. 生成 mobi 電子書。
gitbook mobi ./ ./book.mobi
[root@localhost book]# gitbook mobi ./ ./book.mobi
info: 7 plugins are installed 
info: 6 explicitly listed 
info: loading plugin "highlight"... OK 
info: loading plugin "search"... OK 
info: loading plugin "lunr"... OK 
info: loading plugin "sharing"... OK 
info: loading plugin "fontsettings"... OK 
info: loading plugin "theme-default"... OK 
info: found 2 pages 
info: found 0 asset files 
info: >> generation finished with success in 6.1s ! 
info: >> 1 file(s) generated
  • 構建 mobi 錯誤:InstallRequiredError: "ebook-convert" is not installed

    • Binary install 安裝 calibre-ebook
sudo -v && wget -nv -O- https://download.calibre-ebook.com/linux-installer.py | sudo python -c "import sys; main=lambda:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main()"
Setting up command-line completion...
Installing zsh completion to: /usr/share/zsh/site-functions/_calibre
Installing bash completion to: /usr/share/bash-completion/completions/calibre
Setting up desktop integration...
Creating un-installer: /usr/bin/calibre-uninstall
Run "calibre" to start calibre
  1. 生成 pdf 文檔。
[root@localhost book]# gitbook pdf ./ ./book.pdf
info: 7 plugins are installed 
info: 6 explicitly listed 
info: loading plugin "highlight"... OK 
info: loading plugin "search"... OK 
info: loading plugin "lunr"... OK 
info: loading plugin "sharing"... OK 
info: loading plugin "fontsettings"... OK 
info: loading plugin "theme-default"... OK 
info: found 2 pages 
info: found 1 asset files 
info: >> generation finished with success in 7.6s ! 
info: >> 1 file(s) generated

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章