python2018년 7월 29일4 min read

Creating an eBook with GitBook

How to write and publish an eBook in PDF, EPUB, and MOBI formats using the markdown-based GitBook system.

FFrank Advenoh
#gitbook#pdf#epub

1. Overview

It is no exaggeration to say that we live in the age of content. Rather than having a particular broadcasting company create content, the era has shifted to one where individuals create great content themselves and publish it on platforms such as YouTube. As eBook readers like RIDIBOOKS have become widespread and increasingly popular, the eBook market now offers various tools and platforms that let individuals create their own books.

In this post, let's take a look at GitBook, a markdown-based eBook authoring system.

1.1 Key Features

  • Authoring with markup languages (e.g., AsciiDoc, Markdown)
  • Ability to integrate and store projects with GitHub repositories
  • GitBook Editor support - Web, GUI (legacy version)
  • Support for various eBook formats (e.g., PDF, EPUB, MOBI)
  • Support for various plugins (e.g., etoc, splitter)

2. Installing GitBook

The installation instructions are written for macOS. To install GitBook, NodeJS must be installed first. If you don't have it, install it with the command below.

$ brew install nodejs

Install the gitbook package via NPM.

$ npm install gitbook-cli -g
$ gitbook --version

To generate eBook formats and PDF, the ebook-convert command is required.

$ brew cask install calibre

The /usr/local/bin folder must be included in the $PATH environment variable.

3. Usage

3.1 Creating Your First GitBook Project

The command below generates the boilerplate for the book. By default, README.md and SUMMARY.md are created.

$ gitbook init

If you want to see a more concrete example instead of the basic boilerplate, download and run the sample below from GitHub.

$ git clone https://github.com/kenshin579/app-korean-catholic-bible.git
$ cd app-korean-catholic-bible/example/gitbook_markup_sample

The command below generates a website so you can also view it in a browser.

$ gitbook serve

3.2 Generating eBooks and PDF

You can output the book in various eBook formats.

$ gitbook pdf ./ ./mybook.pdf
$ gitbook epub ./ ./mybook.epub
$ gitbook mobi ./ ./mybook.mobi

4. Plugins

GitBook provides plugins that extend its various features. Let's look at how to find which plugins are available and how to install them.

4.1 How to Find Plugins

You can search for plugins with the features you want on the GitBook plugin site.

4.2 Configuring and Installing Plugins

Add the plugins you want to the book.json file in the root directory, and if needed, configure each plugin as well.

$ vi book.json
[
  {
    "plugins": ["myPlugin", "anotherPlugin"]
  },
  {
    "pluginsConfig": {
      "myPlugin": ""
    }
  }
]

After configuring, install the added plugins with the command below.

$ gitbook install

5. FAQ

  • The README.md in the root directory is also used on GitHub. How can I set a different README.md in GitBook?
    • Modify book.json as follows.
$ vi book.json
"structure" : {
  "readme": "INTRO.md"
}

6. GitBook Pages Examples

GitBook is widely used in universities and for personal sites. It would be helpful to look at the examples below to see what various plugins are used and how GitBook has been customized.

7. References

관련 글