GitBook is a Node.js-based command-line tool that supports Markdown and AsciiDoc syntax formats, and can output eBooks in HTML, PDF, eBook, and other formats.
Install node.js
Before using the gitbook tool, the computer needs to install node.js environment, and after installation, you can check the version command to test whether the installation is successful:
Install Gitbook
Gitbook is installed with npm, command line:
Run the command below to see the GitBook version to verify that the installation was successful.
Install historical versions
gitbook-cli makes it easy to download and install other versions of GitBook to test your books:
Using gitbook ls-remote enumerates the versions that can be downloaded.
Markdown editor
Here we use Markdown syntax as the writing language for our documents, we need to prepare a Markdown editor, we can find many Markdown editors on the market, such as Typora, MacDown, Bear, MarkdownPad, MarkdownX, JetBrains' IDE (requires plugin installation), Atom, Jianshu, CSDN and GitBook's own one GitBook Editor and so on.
I have VS code development tools installed on my computer, vs code supports markdown by default, I only need to install a preview plugin artifact: Markdown Preview Enhanced, and I will use it!
Recommended by friends Editor typora, address:The hyperlink login is visible.
Initialize a book
GitBook can set up a boilerplate:
If you wish to create a book into a new directory, you can do so by running gitbook init ./directory.
After execution, you will see two more files - README.md and SUMMARY.md, which do the following:
README.md - The introduction of the book is written in this document SUMMARY.md - The catalog structure of the book is configured here
I'm not familiar with markdown syntax, so just write a few sentences!
Generate static web pages
Generate static web pages and run servers
All of the above will be generated in the book catalog _book.
The serve command can also specify the port:
When generating, specify the version of gitbook, and it will not be downloaded locally first
Lists all local gitbook versions
List the versions of gitbook that are available remotely
Install the corresponding gitbook version
Update to the latest version of gitbook
Uninstall the corresponding gitbook version
Specifies the level of log
Output error message
Summary
GitBook uses SUMMARY.md files to define the structure of the book's chapters and subchapters. SUMMARY.md File is used to generate the table of contents of the book.
The format of SUMMARY.md is a list of links. The title of the link will serve as the title of the chapter, and the link will be targeted at the path to that chapter file.
Adding a nested list to the parent chapter creates a child chapter.
Simple example:
Then we go back to the command line and run the gitbook init command again in the mybook folder. GitBook looks for directories and files described in SUMMARY.md files,If not, it is created。
Output PDF, ePub or mobi files
If you want to generate a pdf version, you can run gitbook pdf, in the same way, if you are exporting epub format, gitbook epub, if it is mobi format, gitbook mobi will do.
If you want to export an e-book in PDF, ePub or mobi format,Requires Calibre eBook Reader/Manager and command line tools, otherwise an error may be reported "EbookError: Error during ebook generation: 'ebook-convert'".
Features of GitBook Special Files:
file | description | | book.json | Configuration Data (optional) | | README.md | Foreword or introduction to the eBook (required) | | SUMMARY.md | E-book catalog (optional) | | GLOSSARY.md | List of vocabulary/annotation terms (optional) | Gitbook General Settings
GitBook allows you to customize your ebook with flexible configurations.
These options are specified in the book.json file. For authors who are not familiar with JSON syntax, you can verify the syntax using tools like JSONlint.
variable | description | | root | The path to the root folder that contains all the book files, except book.json | | structure | Specify paths for readme, abstracts, glossaries, etc | | title | Your book title, the default value is extracted from the README. On GitBook.com, this field is pre-populated. | | descrip{filter}tion | The description of your book, the default value is extracted from the README. On GitBook.com, this field is pre-populated. | | author | Author's name. On GitBook.com, this field is pre-populated. | | isbn | ISBN | | language | The language type of this book is ISO code. The default value is en | | direction | Text reading order. It can be RTL (right-to-left) or LTR (left-to-right), and the default value depends on the value of the language. | | gitbook | The GitBook version should be used. Use the SemVer specification and accept conditions similar to "> = 3.0.0". |
|