GitBook is a command line tool (and Node.js library) for building beautiful books using GitHub/Git and Markdown (or AsciiDoc). Here is an example: Learn Javascript.
You can publish and host book easily online using gitbook.com, a web-editor is also available.
Stay updated by following @GitBookIO on Twitter or GitBook on Facebook.
Complete documentation is available at help.gitbook.com.
GitBook can be installed from NPM using:
$ npm install gitbook-cli -g
Create the directories and files for a book from its SUMMARY.md file (if existing) using
$ gitbook init
You can serve a repository as a book using:
$ gitbook serve
Or simply build the static website using:
$ gitbook build
GitBook can generate your book in the following formats:
book
will be used.
gitbook pdf ./myrepo ./mybook.pdf
gitbook epub ./myrepo ./mybook.epub
gitbook mobi ./myrepo ./mybook.mobi
gitbook build ./myrepo --format=json
.A book is a Git repository containing at least 2 files: README.md
and SUMMARY.md
.
Typically, this should be the introduction for your book. It will be automatically added to the final summary.
The SUMMARY.md
defines your book's structure. It should contain a list of chapters, linking to their respective pages.
Example:
# Summary
This is the summary of my book.
* [section 1](section1/README.md)
* [example 1](section1/example1.md)
* [example 2](section1/example2.md)
* [section 2](section2/README.md)
* [example 1](section2/example1.md)
Files that are not included in SUMMARY.md
will not be processed by gitbook
.
GitBook supports building books written in multiple languages. Each language should be a sub-directory following the normal GitBook format, and a file named LANGS.md
should be present at the root of the repository with the following format:
* [English](en/)
* [French](fr/)
* [Español](es/)
You can see a complete example with the Learn Git book.
Allows you to specify terms and their respective definitions to be displayed in the glossary. Based on those terms, gitbook
will automatically build an index and highlight those terms in pages.
The GLOSSARY.md
format is very simple :
# term
Definition for this term
# Another term
With it's definition, this can contain bold text and all other kinds of inline markup ...
A set of variables can be defined in the book.json
:
{
"variables": {
"host": "mybook.com"
}
}
These variables can be used in the markdown files:
The host is {{ book.host }}
You can also use condition with these variables:
{% if book.host == "mybook.com" %}
{% else %}
{% endif %}
Variables of book.json
are available in the book
namespace. You can also access informations about the file
itself and the gitbook
version:
My file is {{ file.path }}
Modified at {{ file.mtime }}
Book built with GitBook {{ gitbook.version }}
You can use "content references," or conrefs, when writing books or documentation using GitBook.
Include a file from the same book:
{% include "./test.md" %}
or from a git repository (with a specific revision):
{% include "git+https://github.com/GitbookIO/documentation.git/README.md#1.0.1" %}
Includes can be used with variables (see Variables and Templating):
{% include book.ref_doc_readme %}
GitBook will read the .gitignore
, .bookignore
and .ignore
files to get a list of files and folders to skip. (The format inside those files follows the same convention as .gitignore
).
Best practices for the .gitignore
is to ignore build files from node.js (node_modules
, ...) and build files from GitBook: _book
, *.epub
, *.mobi
and *.pdf
(Download GitBook.gitignore).
A cover image can be set by creating a file: /cover.jpg. The best resolution is 1800x2360. The generation of the cover can be done automatically using the plugin autocover.
A small version of the cover can also be set by creating a file: /cover_small.jpg.
Since version 2.0.0, AsciiDoc can be used instead of Markdown, simply replace the .md
by the .adoc
extension. Chapters in the summary are detected from an ordered list in the SUMMARY.adoc
.
The platform GitBook.com is like an "Heroku for books": you can create a book on it (public, paid, or private) and update it using git push.
Plugins can be used to extend your book's functionality. Read GitbookIO/plugin for more information about how to build a plugin for GitBook.
Plugins needed to build a book can be installed using: gitbook install ./
. You can find plugins at plugins.gitbook.com.
You can use the options --log=debug
and --debug
to get better error messages (with stack trace). For example:
$ gitbook build ./ -- log=debug --debug
To use the latest commit from GitBook/gitbook
with gitbook-cli
:
$ git clone https://github.com/GitbookIO/gitbook.git ./gitbook
$ gitbook versions:link 2.0.0 ./gitbook
Now the version tag 2.0.0
wil be associated with the ./gitbook
folder.
You can uninstall it using: gitbook versions:uninstall 2.0.0
.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。