GitBook 制作电子书详细教程

 更新时间:2016年07月11日 15:11:56   投稿:lqh  
本文主要介绍GitBook如何制作电子书,在使用过程中经常出现的问题以及解决办法,希望能帮助到有需要的同学

gitbook安装:

 https://nodejs.org/#download 

下载node.js源代码(点击绿色的INSTALL),

解压

./configure
make
make install 

成功执行后,npm就被安装好了。

2. gitbook 安装命令

npm install -g gitbook-cli


gitbook -V 

查看gitbook是否安装成功。

ref

===

1. wanqingwong.com/gitbook-zh/index.html

gitbook使用

===========

1. 根据目录生成图书结构

1.1 README.md 与 SUMMARY编写

README.md

这个文件相当于一本Gitbook的简介。

$ mkdir test_gitbook
$ touch README.md

SUMMARY.md

这个文件是一本书的目录结构,使用Markdown语法,

如我们这本书的SUMMARY.md:

$ touch SUMMARY.md
$ vim SUMMARY.md

输入

* [简介](README.md)
* [第一章](chapter1/README.md)
 - [第一节](chapter1/section1.md)
 - [第二节](chapter1/section2.md)
* [第二章](chapter2/README.md)
 - [第一节](chapter2/section1.md)
 - [第二节](chapter2/section2.md)
* [结束](end/README.md)

1.2 生成图书结构

当这个目录文件创建好之后,我们可以使用Gitbook

的命令行工具将这个目录结构生成相应的目录及文件:

$ gitbook init
$ tree . #查看建立的目录和文件

├── chapter1
│   ├── README.md
│   ├── section1.md
│   └── section2.md
├── chapter2
│   ├── README.md
│   ├── section1.md
│   └── section2.md
├── end
│   └── README.md
├── README.md
└── SUMMARY.md

我们可以看到,gitbook给我们生成了与SUMMARY.md所
对应的目录及文件。

每个目录中,都有一个README.md文件,相当于一章的说明。

2. 生成图书

2.1 输出为静态网站

你有两种方式输出一个静态网站:

2.1.1 本地预览时自动生成

当你在自己的电脑上编辑好图书之后,你可以使用Gitbook
的命令行进行本地预览:

$ gitbook serve .

然后浏览器中输入:

 http://localhost:4000 

这样就可以预览生
成的以网页形式组织的书籍。

这里你会发现,你在你的图书项目的目录中多了一个名为
_book的文件目录,而这个目录中的文件,即是生成的静态
网站内容。

使用build参数生成到指定目录

与直接预览生成的静态网站文件不一样的是,使用这个命令,
你可以将内容输入到你所想要的目录中去:

$ mkdir /tmp/gitbook
$ gitbook build --output=/tmp/gitbook

2.2 输出PDF

输入为PDF文件,需要先使用NPM安装上gitbook pdf:

$ sudo npm install gitbook-pdf -g

我在执行上面这条命令的时候出现了下面的错误:

***************************************************

Downloading http://cdn.bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-i686.tar.bz2
Saving to /usr/local/lib/node_modules/gitbook-pdf/node_modules/phantomjs/phantomjs/phantomjs-1.9.7-linux-i686.tar.bz2
Error: connect ETIMEDOUT
  at exports._errnoException (util.js:746:11)
  at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
npm ERR! Linux 3.2.0-4-686-pae
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "gitbook-pdf" "-g"
npm ERR! node v0.12.7
npm ERR! npm v2.11.3
npm ERR! code ELIFECYCLE


npm ERR! phantomjs@1.9.7-5 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the phantomjs@1.9.7-5 install script 'node install.js'.
npm ERR! This is most likely a problem with the phantomjs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!   node install.js
npm ERR! You can get their info via:
npm ERR!   npm owner ls phantomjs
npm ERR! There is likely additional logging output above.


npm ERR! Please include the following file with any support request:
npm ERR!   /home/wangxq/repository/phantomjs/npm-debug.log

***************************************************

 由错误报告内容的第一行可以知道,发生错误的原因是下载

 phantomjs发生了错误,因此我们需要手动下载和安装。

 解决方法:[1]

$ git clone git://github.com/ariya/phantomjs.git
$ sudo apt-get install build-essential g++ flex bison gperf ruby perl \
 libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev \
 libpng-dev libjpeg-dev python libx11-dev libxext-dev    #安装编译需要的工具和依赖
$ cd phantomjs
$ git checkout 1.9.7 #注意:这里的1.9.7是phantom的版本号,可以由错误报告的第一行找出 
$ ./build.sh --jobs 4
$ sudo cp bin/phantomjs /bin/
$ sudo npm install gitbook-pdf -g #重新进行安装

 然后,使用下面的命令,要PDF文件,首先安装依赖库:

$ sudo apt-get install calibre 
$ gitbook -v 2.1.0 pdf .

 发生错误:

*****************************************************

info: start conversion to pdf ....ERROR


Error: Command failed: /bin/sh -c ebook-convert /tmp/tmp-29384ctltwbk/SUMMARY.html /tmp/tmp-29384ctltwbk/index.pdf --title="" --comments="这本书是gitbook的一个例子" --language="en" --book-producer="GitBook" --publisher="GitBook" --chapter="descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter ')]" --chapter-mark="pagebreak" --page-breaks-before="/" --level1-toc="descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-1 ')]" --level2-toc="descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-2 ')]" --level3-toc="descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-3 ')]" --no-chapters-in-toc --max-levels="1" --breadth-first --margin-left="62" --margin-right="62" --margin-top="56" --margin-bottom="56" --pdf-default-font-size="12" --pdf-mono-font-size="12" --paper-size="a4" --pdf-header-template="<p class='header'><span></span></p>" --pdf-footer-template="<p class='footer'><span>_SECTION_</span> <span style='float:right;'>_PAGENUM_</span></p>"
Usage: ebook-convert input_file output_file [options]


Convert an ebook from one format to another.


input_file is the input and output_file is the output. Both must be specified as the first two arguments to the command.


The output ebook format is guessed from the file extension of output_file. output_file can also be of the special format .EXT where EXT is the output file extension. In this case, the name of the output file is derived the name of the input file. Note that the filenames must not start with a hyphen. Finally, if output_file has no extension, then it is treated as a directory and an "open ebook" (OEB) consisting of HTML files is written to that directory. These files are the files that would normally have been passed to the output plugin.


After specifying the input and output file you can customize the conversion by specifying various options. The available options depend on the input and output file types. To get help on them specify the input and output file and then use the -h option.


For full documentation of the conversion system see
http://manual.calibre-ebook.com/conversion.html


Whenever you pass arguments to ebook-convert that have spaces in them, enclose the arguments in quotation marks.


ebook-convert: error: no such option: --pdf-default-font-size

*****************************************************

解决方法[2]

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


$ gitbook -v 2.1.0 pdf . # 重新执行命令生成pdf,目标文件为book.pdf

ref

===

1. http://phantomjs.org/build.html
2. http://calibre-ebook.com/download_linux

问题

===

1. 如果输入gitbook init命令,出现Installing version 2.1.0,

需要耐性等待安装。

       以上就是我整理的gitbook的安装与使用资料,谢谢大家支持!

相关文章

  • shell耗时计算的实现

    shell耗时计算的实现

    本文主要介绍了shell耗时计算的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-01-01
  • Linux下JDK中文字体乱码的解决方法

    Linux下JDK中文字体乱码的解决方法

    下面小编就为大家带来一篇Linux下JDK中文字体乱码的解决方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-02-02
  • Linux 中的 Install命令

    Linux 中的 Install命令

    install命令的作用是安装或升级软件或备份数据,它的使用权限是所有用户。 本文重点给大家介绍Linux 中的 Install命令,感兴趣的朋友一起看看吧
    2017-09-09
  • linux下部署kodexplorer的方法

    linux下部署kodexplorer的方法

    下面小编就为大家带来一篇linux下部署kodexplorer的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • Shell如何遍历包含空格的文本详解

    Shell如何遍历包含空格的文本详解

    这篇文章主要给大家介绍了关于Shell如何遍历包含空格的文本的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-04-04
  • Shell中比较大小简洁总结

    Shell中比较大小简洁总结

    这篇文章主要介绍了Shell中比较大小简洁总结,本文总结了在shell中比较变量大小的一些方法,需要的朋友可以参考下
    2014-12-12
  • 使用Bash脚本自动化清理Nacos日志文件的实现方法

    使用Bash脚本自动化清理Nacos日志文件的实现方法

    在现代的分布式系统中,Nacos作为服务发现、配置管理和动态服务管理的核心组件,其日志文件的管理显得尤为重要,随着系统的运行,日志文件会不断累积,占用大量磁盘空间,本文将介绍如何通过一个简单的 Bash 脚本自动化清理 Nacos 的日志文件,需要的朋友可以参考下
    2025-04-04
  • linux shell流程控制语句实例讲解(if、for、while、case语句实例)

    linux shell流程控制语句实例讲解(if、for、while、case语句实例)

    linux shell有一套自己的流程控制语句,其中包括条件语句(if),循环语句(for,while),选择语句(case)。下面我将通过例子介绍下,各个语句使用方法
    2014-04-04
  • ./ 和 sh 的使用区别详解

    ./ 和 sh 的使用区别详解

    这篇文章主要介绍了./ 和 sh 的使用区别详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-09-09
  • Shell脚本实现C语言代码行数统计

    Shell脚本实现C语言代码行数统计

    这篇文章主要介绍了Shell脚本实现C语言代码行数统计,本文直接给出实现代码,需要的朋友可以参考下
    2015-05-05

最新评论