Column catalog
- Gitbook introduction
- Gitbook installation
- Gitbook is easy to use
- Gitbook plug-in introduction
- Gitbook error handling
Column details
Gitbook
Gitbook introduction
GitBook is a command line tool based on Node.js. You can use Github/Git and Markdown to produce beautiful electronic documents. GitBook default output format, generated static site * PDF: need to install gitbook-pdf * eBook: need to install ebook-convert * single HTML page: JSON: Generally used for eBook debugging or metadata extraction. To make an eBook using GitBook, you must have two files: Readme.md [main page] summary.md [sidebar page]Copy the code
Gitbook installation
-v # Install Gitbook multiversion hosting tool to host multiple versions of Gitbook at the same time. Gitbook -v install Gitbook -v install Gitbook -v install Gitbook -cli -g It is recommended to use 3.0.0 gitbook fetch 3.0.0 # to enter your project folder, Gitbook init # Generate two basic files: readme. md and summary. md # Start Gitbook Serve # Specify the Gitbook version to start Gitbook Serve --gitbook=3.0.0 # Gitbook --help # uninstall gitbook Specify that the Gitbook version generates static files, Gitbook build will be downloaded first if not locally --gitbook=3.0.0 # List all gitbook versions locally gitbook ls # List all gitbook versions remotely available gitbook ls-remote # Gitbook build --log=debug # Output error message gitbook builid Gitbook PDF. [PDF_Name]Copy the code
Gitbook is easy to use
Write the main interface of the Gitbook project in readme. md, and summary. md is an example of the property readme. md in the sidebar of the Gitbook interface
# Introduction to the main interface------ A brief description of this document### Directory introduction
* [Directory 1] (1.md)
* [Directory 2] (2.md)
* [Directory 3] (2.md)
* [Directory of 4] (4.md)
Copy the code
The SUMMARY. The md example
* [Directory 1] (1.md)
* [Directory 2] (2.md)
* [Directory 3] (2.md)
* [Directory of 4] (4.md)
Copy the code
Json can be created in the project root directory to implement the global configuration file information
{
"title": "MedusaSorcerer's blog document."."author": "MedusaSorcerer"."description": "MedusaSorcerer's blog document."."language": "zh-hans"."gitbook": "3.0.0"."structure": {
"readme": "README.md"
},
"plugins": [
"-highlight"."-github"."-search"."-lunr"."livereload"."back-to-top-button"."code"."prism"."copy-code-button"."search-pro"."splitter"."-sharing-plus"."tbfed-pagefooter"."click-reveal"]."pluginsConfig": {
"tbfed-pagefooter": {
"modify_label": "Revision date of this document:"."modify_format": "YYYY-MM-DD HH:mm:ss"}},"links": {
"sidebar": {
"Blog homepage": "https://juejin.cn/user/2805609406139950"
},
"sharing": {
"google": false."facebook": false."twitter": false."weibo": false."all": false}}}Copy the code
The keyword | describe | The sample |
---|---|---|
title | The project title | MedusaSorcerer’s blog docs |
author | Project the author | MedusaSorcerer |
description | Project Description | – |
language | The project language | See the table below |
gitbook | Gitbook Version information | 3.0.0 |
structure | Structural information | {“readme”: “readme.md “} specifies the file for readme |
plugins | Name of the plug-in that you want to install or disable | – |
pluginsConfig | The installed plug-in requires a custom configuration | – |
links.sidebar | Add additional links to the document | {” Blog home “:”Juejin. Cn/user / 280560…{name: address} |
links.sharing | Configuration to enable or disable icon links for documents | – |
List of supported languages, differences between versions, for reference only
Language shorthand | describe | Language shorthand | describe |
---|---|---|---|
en | English | ar | The Arabic language |
bn | Malay | cs | Czech |
de | German | es | Spanish |
fa | Persian | fi | Finnish |
fr | French | he | Hebrew |
it | Italian | ja | Japanese |
ko | Korean | no | Norwegian |
pl | polish | pt | Portuguese |
ro | Romanian | ru | Russian |
sv | Swedish | uk | Ukrainian |
vi | Vietnamese | – | – |
zh-hans | Simplified Chinese | zh-tw | Traditional Chinese |
Gitbook plug-in introduction
Highlight Search sharing font- Settings Livereload is enabled by default when a plugin is installed using the “plug-in name” to register in the plugins
The plug-in name | describe | Take a chestnut |
---|---|---|
highlight | Code highlighting | – |
search | Navigation bar English search function | – |
font-settings | font | – |
livereload | Reload the GitBook in real time | – |
disqus | Add a Disqus comment | “plugins”: [ “disqus” ]. “pluginsConfig”: { “disqus”: { “shortName”: “gitbookuse” } } |
search-pro | Support Chinese search, need to be The default search plugin is removed |
“plugins”: [ “-search”, “search-pro” ]. “pluginsConfig”: { “search-pro”: { “cutWordLib”: “nodejieba”, “defineWord” : [“Gitbook Use”] } } |
advanced-emoji | Emoji support | “plugins”: [ “advanced-emoji” ] |
github | Add the Github icon | “plugins”: [ “github” ]. “pluginsConfig”: { “github”: { “url”: “Juejin. Cn/user / 280560… } } |
ace | Make gitbook support ACE | “plugins”: [ “ace” ] |
emphasize | Background the text | “plugins”: [ “emphasize” ] |
katex | Support mathematical formula | “plugins”: [ “katex” ] |
include-codeblock | Use code block format to display Shows the contents of the contained file |
“plugins”: [ “include-codeblock” ] |
mermaid | Support rendering Avi charts | “plugins”: [ “mermaid” ] |
splitter | Make the sidebar width freely adjustable | “plugins”: [ “splitter” ] |
sharing | Share current page, default plug-in | “plugins”: [ “-sharing” ] “pluginsConfig”: { “sharing”: { “weibo”: true, “facebook”: true, “twitter”: true, “google”: false, “instapaper”: false, “vk”: false, “all”: [ “facebook”, “google”, “twitter”, “weibo”, “instapaper” ] } } |
tbfed-pagefooter | Add a footer to the page | “plugins”: [ “tbfed-pagefooter” ]. “pluginsConfig”: { “tbfed-pagefooter”: { “copyright”:”Copyright © zhangjikai.com 2015″, “Modify_label “:” This file was modified at: “, “modify_format”: “YYYY-MM-DD HH:mm:ss” } } |
toggle-chapters | Make the section catalog on the left collapsible | “plugins”: [ “toggle-chapters” ] |
sectionx | Display the page in chunks | “plugins”: [ “sectionx” ] |
codeblock-filename | Add the file name for the code block | “plugins”: [ “codeblock-filename” ] |
ga | Google statistics | “plugins”: [ “ga” ]. “pluginsConfig”: { “ga”: { “token”: “UA-XXXX-Y” } } |
baidu | Baidu statistics | “plugin”: [ “baidu” ]. “pluginsConfig”: { “baidu”: { “token”: “YOUR TOKEN” } } |
Gitbook error handling
- perform
npm install gitbook-cli -g
Download failedGo to your Users\ Current User \AppData\Roaming\ NPM \node_modules directory and check whether there is a gitbook-cli directory if there is one, delete the gitbook-cli directory If the directory does not exist, Uninstall the Gitbook legacy files using NPM and retry the downloadCopy the code
- After the modified project file is saved,
gitbook serve
Hot loading is not supported
When you modify the Gitbook project and save it, the serve restart prompts that the mkdir operation cannot be used, so that the purpose of restart cannot be achieved
Then you need to do the following:- Find what you downloaded
gitbook
Version folder: normally locatedUsers\ Current user \.gitbook\versions\
The folder name corresponding to the version number will be displayed below - Find it in the corresponding version folder
lib\cli\serve.js
file - Copy the following code to place
serve.js
In the file/* First line of code */ const fs=require("fs"); /* Any blank space */ function deleteFolder(path) { let files = []; if( fs.existsSync(path) ) { files = fs.readdirSync(path); files.forEach(function(file,index){ let curPath = path + "/" + file; if(fs.statSync(curPath).isDirectory()) { deleteFolder(curPath); } else{ fs.unlinkSync(curPath); }}); fs.rmdirSync(path); }}Copy the code
- in
serve.js
Find the bodygenerateBook
- Within the function
var outputFolder = getOutputFolder(args);
Write the following code on another lineif (server.isRunning()) deleteFolder(outputFolder) Copy the code
- Save and exit, restart Gitbook, and find that hot loading has taken effect
Note:When you stop the service, if the service does not automatically delete the _book folder, you need to manually delete the _book folder` `
- Find what you downloaded
- Gitbook not found after installation
gitbook
instructionNeed to add Gitbook variable Path Users\ Current User \AppData\Roaming\ NPM in your environmentCopy the code
- use
gitbook pdf . pdfname.pdf
The PEF file encoding is incorrect① Download the installation package from https://calibre-ebook.com/ and install it locally ② Right-click the installation desktop icon to find the installation PATH and copy it ③ Right-click my computer -> Properties -> Advanced System Settings -> Environment Variables -> User Variables -> Select PATH -> Edit ④ Paste the file path to the blank line at the end of the file to save and exit. ⑤ Open CMD or another interactive window and run the gitbook commandCopy the code