Gitbook Installation and use

Source: Internet
Author: User

Nonsense not to say, direct subject:


Gitbook Installation

===========


1. Install NPM
Download the node. JS source code from the website https://nodejs.org/#download (click the Green Install),
Extract
./configure
Make
Make install
After successful execution, NPM is installed.


2. Gitbook Installation
NPM install-g GITBOOK-CLI


Gitbook-v
See if the Gitbook installation was successful.


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


Gitbook use
===========
1. Generate the book structure according to the catalogue


1.1 Readme.md and summary writing
Readme.md
This file is equivalent to a Gitbook profile.
$ mkdir Test_gitbook
$ Touch Readme.md


Summary.md
This file is a directory structure of a book, using the markdown syntax,
As the summary.md of our book:
$ Touch Summary.md
$ vim Summary.md


Input


* [Introduction] (README.MD)
* [First chapter] (CHAPTER1/README.MD)
-[first section] (CHAPTER1/SECTION1.MD)
-[section II] (CHAPTER1/SECTION2.MD)
* [Chapter II] (CHAPTER2/README.MD)
-[first section] (CHAPTER2/SECTION1.MD)
-[section II] (CHAPTER2/SECTION2.MD)
* [end] (END/README.MD)


1.2 Building a book structure
When this directory file is created, we can use Gitbook.
Command-line tool to generate the appropriate directory and files for this directory structure:
$ gitbook Init
$ tree. #查看建立的目录和文件
.
├──chapter1
│├──readme.md
│├──section1.md
│└──section2.md
├──chapter2
│├──readme.md
│├──section1.md
│└──section2.md
├──end
│└──readme.md
├──readme.md
└──summary.md


As we can see, Gitbook gives us the creation of the SUMMARY.MD
The corresponding directories and files.


In each directory, there is a readme.md file, which is equivalent to the description of a chapter.




2. Generate Books


2.1 Output as static website
You have two ways of outputting a static web site:
2.1.1 automatically generated when local preview
Once you've edited your books on your computer, you can use Gitbook
Local preview of the command line:


$ gitbook serve.


Then enter http://localhost:4000 in the browser to preview the live
of books organized in Web form.
Here you will find that you have more than one name in the directory of your book project
_book files directory, and the files in this directory are generated statically
Website content.
Build to the specified directory using the build parameter
Unlike a static Web site file that is generated directly from the preview, using this command,
You can enter the content into the directory you want:
$ mkdir/tmp/gitbook
$ Gitbook Build--output=/tmp/gitbook


2.2 Output PDF
To enter as a PDF file, you need to first install the Gitbook PDF using NPM:
$ sudo npm install gitbook-pdf-g
The following error occurred while I was executing the above command:
***************************************************
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! [Email protected] Install: ' Node Install.js '
NPM err! Exit Status 1
NPM err!
NPM err! Failed at the [email protected] Install script ' node Install.js '.
NPM err! Likely a problem with the PHANTOMJS package,
NPM err! Not with NPM itself.
NPM err! Tell the author, 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


***************************************************
The first line of the content of the error report is known, and the reason for the error is to download
Phantomjs An error occurred, so we need to download and install it manually.


WORKAROUND: [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 #注意: Here the 1.9.7 is the Phantom version number, which can be found by the first line of the error report
$./build.sh--jobs 4
$ sudo cp bin/phantomjs/bin/
$ sudo npm install gitbook-pdf-g #重新进行安装


Then, using the following command, to PDF files, first install the dependent libraries:


$ sudo apt-get install calibre
$ gitbook-v 2.1.0 PDF.
Error occurred:
*****************************************************
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=" This book is an example of 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=" ""--margin-right= "62"-- margin-top= "--margin-bottom=" "--pdf-default-font-size=" "--pdf-mono-font-size=" "--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 and 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. The the name of the output file is derived the name of the input file. Note that the filenames must isn't start with a hyphen. Finally, if output_file have no extension, then it's treated as a directory and an "open ebook" (OEB) consisting of HTML F Iles is written to that directory. These files is the files that would normally has been passed to the output plugin.


After specifying, the input and output file can customize the conversion by specifying various options. The available options depend on the input and output file types. 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 has spaces in them, enclose the arguments in quotation marks.


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


*****************************************************
Workaround [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. # re-execute command to generate PDF, target file is Book.pdf


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


Problem
===
1. If you enter the Gitbook init command, installing version 2.1.0 appears,
Patience is required for installation.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Gitbook Installation and use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.