The introduction

  • Explains how to use the tools provided by Gitbook to develop a book document locally and deploy it on your own service

1. Install node

Referring to my other article, I suggest using NVM to manage node version links

2. Gitbook client installation

After node is installed on NVM, NPM is also installed successfully. Use NPM to install gitbook client

npm install gitbook-cli -g
Copy the code

Initialize the gitbook directory

Create a new gitbook directory

mkdir gitbokk
cd gitbook
gitbook init
Copy the code
  • Gitbook Init creates the readme. md and summary. md files in the empty project
  • The readme. md file is the introduction file for the project.
  • SUMMARY. Md is a catalog of gitbook books

4. Start the service locally

gitbook serve
Copy the code
Live reload server started on port: 35729 Press CTRL+C to quit ... info: 21 plugins are installed info: 15 explicitly listed info: loading plugin "search-pro"... OK info: loading plugin "back-to-top-button"... OK info: loading plugin "chapter-fold"... OK info: loading plugin "expandable-chapters"... OK info: loading plugin "highlight"... OK info: loading plugin "tbfed-pagefooter"... OK info: loading plugin "code"... OK info: loading plugin "flexible-alerts"... OK info: loading plugin "popup"... OK info: loading plugin "localized-footer"... OK info: loading plugin "livereload"... OK info: loading plugin "sharing"... OK info: loading plugin "fontsettings"... OK info: loading plugin "theme-default"... OK info: found 20 pages info: found 25 asset files warn: "options" property is deprecated, use config.get(key) instead warn: "this.generator" property is deprecated, use "this.output.name" instead warn: "navigation" property is deprecated warn: "Book" property is deprecated, use "this" directly instead info: >> Generation finished with success in 2.6s! Starting server ... Serving book on http://localhost:4000Copy the code

5, packaging,

gitbook build
Copy the code

A _book directory is generated in the current directory

In the _book folder there is an index.html file, which is the HTM entry of the document site. Copy the _book folder to the server, and then direct the Web service entry to index.html to complete the deployment of the document site.

If you want to see a detailed record of the output directory, use gitbook build./ –log=debug –debug to build the view

6. Generate e-books

gitbook pdf ./ ./mybook.pdf


gitbook epub ./ ./mybook.epub


gitbook mobi ./ ./mybook.mobi
Copy the code

7. Configuration file explanation

If you want to personalize your site in more detail or use plug-ins, you need to use profiles. After the configuration file is written, the service needs to be restarted or repackaged to apply the configuration

Json {"title": "my first book ", "author" : "[email protected]", "description" :" my first book description, very good ", "Keywords ": "Gitbook User manual, Markdown, Gitbook,", "language" : "zh-hans",// language" plugins": [ "-lunr", "-search", "search-pro", "back-to-top-button", "chapter-fold", "expandable-chapters", "highlight", "tbfed-pagefooter", "code", "flexible-alerts", "popup", "localized-footer" ], "pluginsConfig": { "localized-footer": { "hline": true, "filename": "./FOOTER.md" }, "theme-default": { "showLevel": true }, "anchor-navigation-ex": {"isShowTocTitleIcon": true}, "tbFed-pagefooter ": {"copyright":"", "modify_label":" This file was last modified at :", "modify_format": "MM - DD YYYY - HH: MM: ss"}, "code" : {" copyButtons ": true}}," links ": {" sidebar" : {" my connection ": "https://www.baidu.com" } }, "styles": { "website": "styles/website.css", "ebook": "styles/ebook.css", "pdf": "styles/pdf.css", "mobi": "styles/mobi.css", "epub": "styles/epub.css" } }Copy the code
  • The title title
  • The author the author
  • Description Indicates the description of the Gitbook website
  • Language Indicates the language used. Zh-hans is simplified Chinese and will be displayed on the page
  • Structure specifies the file names for Readme, Summary, Glossary, and Languages. Here are the variables and default values for these files:
Variable Description structure.readme Readme file name (defaults to README.md) structure.summary Summary file name (defaults to SUMMARY.md) structure.glossary Glossary file name (defaults to GLOSSARY.md) structure.languages Languages File name (defaults to langs.md) For example, if you want to name the readme file, use the following configuration: structure {"readme": "Introduce.md"}, with this configuration, the Gitbook service does not look for readme files, but for introduction files as project descriptions, thus treating the readme files as the repository documentation entirely.Copy the code
  • A list of plugins to use, all of which are written here and then installed using Gitbook Install.
  • PluginsConfig configuration information for the pluginsConfig plug-in. If the plug-in requires configuration parameters, fill them in here.
  • Links Adds link information to the navigation bar
"Links" : {" sidebar ": {" personality link 1" : "https://www.baidu.com"}}Copy the code
  • Styles Custom page styles. Each format corresponds to the CSS file
"styles": {
    "website": "styles/website.css",
    "ebook": "styles/ebook.css",
    "pdf": "styles/pdf.css",
    "mobi": "styles/mobi.css",
    "epub": "styles/epub.css"
}
Copy the code

8. Practical plug-ins

  • Segmentfault.com/a/119000001…
  • www.cnblogs.com/mingyue5826…

9. Bug problems

  • Error: ENOENT: no such file or directory, stat

Find. Gitbook \ versions \ 3.2.3 \ lib \ output \ website \ copyPluginAssets js

Confirm: true change confirm: falseCopy the code
  • Error: Error with command “svgexport”
npm install svgexport -g
Copy the code

10. Deploy to GitHub Pages

Github create A new repository CD _book git init git add -a git commit -m 'init' git remote add origin <yourgit> git branch -m main git push -u origin mainCopy the code

In github repository, go to Settings -> Github Pages -> Source and select Gh-Pages Branch. Then click the Save button and under Github Pages you will see a url. This url is the final site.

At the end

With you mutual encouragement, I hope to help you