gitbook installation and use. It's enough to read this article

Gitbook tutorial

GitBook installation

GitBook is a tool that can quickly make e-books in various formats using Markdown syntax. It is a command line tool based on Node.js, which can be used to make exquisite e-books. First, we have to download Nodejs and install it

Note: up to the current Gitbook V3.2.3 version, you need to use the v10 + version of NodeJs, otherwise various errors will be generated.

It is recommended to download v10.23.1. I can't even try the latest version on the official website.

Install Nodejs first

Nodejs historical version download connection After downloading, you can directly install it in the next step.

After installing nodejs, enter the command to check whether the installation is successful. If the command is invalid, check whether the environment variable is configured.

$ node -v                                                

Installing GitBook

Next, install GitBook cli using the npm command. It is a utility that installs and uses multiple versions of GitBook on the same system. It will automatically install the required version of the GitBook program. (it may take some time, just wait patiently)

$ npm install gitbook-cli -g

Check whether the installation is successful through the gitbook -V command (it may take some time, just wait patiently). V is capitalized

$ gitbook -V

Gitbook basic usage

  • Gitbook document directory structure
GitBook The basic directory structure is as follows
|- book.json		//E-book profile
|-		//Main description documents of e-books
|-		//Catalogue of e-books
|- chapter-1/		//Chapter 1 folder of e-book (chapter-1 is the folder name and can be customized)
	|-	    //Documentation for Section 1
 	|- Document		//Subsection 1 below this section
    |- Document		//Section 2 below
|- chapter-2/		//Chapter 2 folder of e-book (chapter-2 is the folder name and can be customized)
	|-	    //Documentation for section 2
 	|- Document		//Section 2 below
    |- Document		//Section 2 below
  • Gitbook initialization

Create a new folder, such as gitbook_test, use the cd command to enter the folder and initialize in the folder.

$ gitbook init

Two files will be automatically generated in the directory, one is the main description file and the other is the directory file

  • Next, write the directory

Use typera to open the file and write the directory. The format is as follows

# Summary
* [Tutorial guide](
* [day01—Environment construction&quick get start](day01—Java development environment /
    * [Environment construction](day01—Java development environment /Environment
    * [Introductory case](day01—Java development environment /Basic
    * [Basic grammar](day01—Java development environment /Introductory
    * [After class practice](day01—Java development environment /After class
* [day02—Type conversion&operator](day02—Type conversion&operator/
    * [Type conversion](day02—Type conversion&operator/Type
    * [operator](day02—Type conversion&operator/
    * [if sentence](day02—Type conversion&operator/if
    * [After class practice](
  • Generate section md files

After writing the directory, in gitbook_ Under the test folder, use the gitbook init command again to generate the md files of each section in a directory.

$ gitbook init

  • Compile and generate static web pages

Will be in gitbook_test directory to generate a_ book folder, which is one of our static sites

$ gitbook build
  • Compile and preview static web pages

First compile and generate a static site, start a 4000 port service, and access it in the browser using localhost:4000

$ gitbook serve

Gitbook profile

Gitbook has a configuration file book.json, in which various plug-ins can be configured to beautify the display and interaction effects of the page. Since there are many plug-ins used, I have written the common configurations and plug-ins here and paste them directly.

Note: the book.json file must be placed in the root directory

    "title": "Java Getting Started tutorial",
    "description": "With the most popular language, take you quickly into Java The gate of the world",
    "author": "Dark horse programmer",
    "": "site",
    "language": "zh-hans",
    "gitbook": "3.2.3",
    "root": ".",
	"plugins": [
	"pluginsConfig": {
		"tbfed-pagefooter": {
			"copyright":"Copyright &copy 2021",
			"modify_label": "This document was revised on:",
			"modify_format": "YYYY-MM-DD HH:mm:ss"
		"hide-element": {
            "elements": [".gitbook-link"]
		"favicon": "favicon.ico",
		"pdf": {
			"pageNumbers": true,
			"fontFamily": "Arial",
			"fontSize": 12,
			"paperSize": "a4",
			"margin": {
				"right": 62,
				"left": 62,
				"top": 56,
				"bottom": 56
		"page-toc-button": {
            "maxTocDepth": 2,
            "minTocSize": 2
       "sectionx": {
          "tag": "b"

	"styles": {
	    "website": "styles/website.css",
	    "ebook": "styles/ebook.css",
	    "pdf": "styles/pdf.css",
	    "mobi": "styles/mobi.css",
	    "epub": "styles/epub.css"

After writing the configuration file, you need to execute the command to install the plug-in (it takes a little time to download the plug-in here, just wait patiently)

$ gitbook install

Gitbook document editing

  • Display mode switching

Any editor that supports markdown syntax can be used for editing. It is recommended to use typera here.

  • Basic markdown syntax
# Primary title
## Secondary title
### Tertiary title

> Reference format

**Text bold**

- Small black dot format

Code here

`Inline code`
  • Document content folding effect

For example, we want to set up a classroom question, but we don't want students to see the answer. You can fold the answer content, and the effect is as follows.

In the md file, you can write it in the following format. This is the display effect of the compiled web page.

<!--sec data-title="Question 1: what does platform mean in cross platform?" data-id="section1" data-show=true data-collapse=true ces-->

Java Cross platform refers to the use of Java Language programs can run on a variety of platforms. The platform here refers to the operating system. Common operating systems include **Windows**,**Linux**,**MacOS**


Note: the attribute value of data ID cannot be repeated if there are multiple folding effects in a page.

  • Precautions and effects

For example, there are often some details that need students' attention, and an eye-catching but intuitive warning effect is as follows.

The md file is written in the following format. After compilation, the warning effect is displayed on the page

> **[!WARNING] **
> We can only say Java The program is cross platform, but Java Virtual machines are not platform specific
  • Friendly prompt effect

For example, there are often some tips to give students some suggestions. You can use the tips. The effects are as follows.

The md file is written in the following format. After compilation, the TIP prompt effect is displayed on the page

> **[!TIP] **
> If you can write this question, you have mastered it **Numerical splitting** The solution of this kind of documents. You can

Gitbook publishing site

If you want your site to be accessible online, you can compile the generated_ book folder, push it to github or gitee for hosting, and start the Page service.

Note: github has not been tried temporarily due to its slow access; gitee has shut down the Page service, so this road is also blocked.

So I found some other ways

  • Push the static to Coding for hosting, with a 6-month free trial period. The specific steps will not be described in detail here
  • Purchase Alibaba cloud, Huawei cloud and other servers and publish the site to the server. The specific steps are not described in detail here

Tags: node.js IDE gitbook

Posted on Fri, 10 Sep 2021 06:31:01 -0400 by matt_wood87