在自己的服务器上安装GitBook

更新时间:2016-08-05

更新说明:
由于在 Linux 内核的机器上安装 Calibre 需要安装的依赖库过多,故不推荐在此类机器上使用格式转换功能。你可以阅读 在自己的电脑上安装 GitBook For Mac 来了解在 Mac 上完美使用 Gitbook .

无意间发现在这个开源的 EBook 制作软件 GitBook,你可以在官网上配置相关信息来和自己的 GitHub 账号绑定来创建自己的 EBook,并且支持生成 PDF、ePub 和 MOBI 三种格式提供下载。
但是我想自己安装 GitBook 来生成 HTML 格式,那样就可以放在自己的网站里面了。
安装过程:

  • 安装基本环境
    • 安装 Git
    • 安装 NVM、Node.js 和 NPM
    • 升级 Python 版本到 2.7.1 以上
  • 安装 GitBook 及 calibre 组件
  • 初始化并生成 Demo
  • 生成 HTML 以及其他格式的文件

安装基本环境

安装 Git

CentOS 安装 Git 的方式可自行搜索

安装 NVM、Node.js 和 NPM

快速搭建 Node.js / io.js 开发环境以及加速 npm

升级 Python 版本到 2.7.1 以上

由于 GitBook 生成多格式的文件需要用到 calibre,calibre 最新版要求 python ≥ 2.7.1 not 3.x。
查看 Python 版本:python,看结果中 Python 的版本是否符合要求。
如果需要升级 Python,请查看:centos 系统升级 python 2.7.3

安装 GitBook 及 calibre 组件

安装 GitBook:

$ npm install gitbook-cli -g

安装 calibre:
Calibre 安装文档 For Linux
我找到的安装代码如下:

wget -nv -O- https://raw.githubusercontent.com/kovidgoyal/calibre/master/setup/linux-installer.py | python -c"import sys; main=lambda x:sys.stderr.write('Download failed\n'); exec(sys.stdin.read()); main('/opt')"

命令的最后 main('/opt')/opt 为 Calibre 的安装目录,可根据需要修改。

初始化并生成 Demo

$ cd /home/
$ mkdir gitbook
$ cd gitbook/
$ mkdir demo
$ cd demo/
$ gitbook init

执行最后一个命令之后会在 /home/gitbook/demo/ 下生成 README.mdSUMMARY.md 两个文件

生成 HTML 以及其他格式的文件

1. 生成完整的静态 HTML:切换到书的目录后 built 即可

$ cd /home/gitbook/demo/
$ gitbook build

会在/home/gitbook/demo/ 目录下生成 _book 目录,即为完整的 HTML 静态网站

2. 生成其他格式的文件
先切换到项目的目录下:比如本机的/home/gitbook/

PDF:

gitbook pdf ./demo ./demo.pdf

ePub:

gitbook epub ./demo ./demo.epub

MOBI:

gitbook mobi ./demo ./demo.mobi

注:需要提前安装Calibre,Gitbook 会使用其中的 ebook-convert 功能组件来完成书籍格式的转换。

我遇到的 Bug

由于我未学习过 node.js 和 Python,在 安装 calibre那一步出错了,导致在 GitBook 生成其他格式文件的时候出问题,生成 pdf 和 mobi 会失败,但是 epub 却成功了

安装 calibre 时的错误信息:

Failed to find directory to install bash completions, using default.
____________________ WARNING ____________________
Setting up completion failed with error:
__________________________________________________
	Traceback (most recent call last):
	 File"site-packages/calibre/linux.py", line 748, in setup_completion
	 File"site-packages/calibre/linux.py", line 505, in write_completion
	 File"site-packages/calibre/gui2/__init__.py", line 8, in <module>
	ImportError: cannot import name QStyle
	
Setting up desktop integration...
____________________ WARNING ____________________
Setting up desktop integration failed with error:
__________________________________________________
	Traceback (most recent call last):
	 File"site-packages/calibre/linux.py", line 781, in setup_desktop_integration
	 File"site-packages/calibre/linux.py", line 1097, in render_img
	ImportError: cannot import name QImage

Creating un-installer: /usr/bin/calibre-uninstall

There were 2 warnings

* Setting up completion failed with error:

* Setting up desktop integration failed with error:

Run"calibre"to start calibre 

ImportError: cannot import name QStyleImportError: cannot import name QImage来看,估计是 Python 少了什么库,希望能解决这个问题的博友指点一下。

参考

  • https://likfe.com
  • https://github.com/GitbookIO/gitbook
  • http://www.calibre-ebook.com/download_linux
  • http://blog.liyibo.org/books-installation-authoring-tool-gitbook
  • https://micro.blog.csdn.net/article/details/45130831

更新 2015-04-26

关于安装过程中出现的 Bug 问题,我查到了如下一些解答:

  1. 在 centos 6.2,python2.7 下安装 QT 4.8.3,pyqt 4.9.5 详细步骤
  2. Building PyQt5 for Python2.7 on a clean Ubuntu 13.10 build machine
  3. ImportError: cannot import name QStyle

我的折中方案

对于 Python 以及 Linux 方面新手而言,安装 py-Qt 相关库是件不太容易的事情。如果只是为了生成 Pdf 等格式的文档,我想到一个折中的方案:

  1. 上传文件到 Github 上
  2. 在 Gitbook 官网注册个账号,创建 book 并关联 Github 账号以及对应的项目
  3. 在 Gitbook 上下载生成的 pdf、mobi 格式的文件

更新 2016-08-05

如果你和我一样安装 Calibre 失败了,要做好文件清理工作:

//卸载 calibre
sudo rm -rf /opt/calibre/*

//清除失效的软连接
cd /usr/bin/
rm -rf ./calibre*
rm -rf ./ebook*
rm -rf fetch-ebook-metadata
rm -rf lrf2lrs
rm -rf lrfviewer
rm -rf lrs2lrf
rm -rf markdown-calibre
rm -rf web2disk

本文地址:https://micro.blog.csdn.net/article/details/45130831
最后声明一下:转载请注明出处!

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值