What is a plug-in
Gitbook
Plug-in is extended GitBook
functions (e-books and websites) in the best way .
As long as Gitbook
the default function is not provided , based on plug-in mechanism can be self-expansion , is the plugin allows Gitbook
much more powerful.
This article will fully introduce the relevant knowledge Plug and focuses on the whole process of plug-in development , only familiar with the plug-in development processes to be targeted aware of in order to develop their own plug-ins.
About Plug-ins Refer to the
Gitbook
Getting Started tutorial Senior Advanced series, focusing on the development of this paper to explainGitbook
the basic flow .
How to find plug-ins
You canEasily search plug-in can also be in Gitbook
Official websitenpmjs
the official website of the search gitbook-plugin-<name>
plug-ins.
Currently
Gitbook
the official has no longer maintain Plugin website, only through thenpmjs
discoveryGitbook
plug-ins.
How to install plug-ins
Once you find the plugin you want to install, you need to add it to your book.json
configuration file, if the file is not self-created.
{
"plugins": ["myPlugin", "anotherPlugin"]
}
You can also use the following command to specify a specific version: [email protected]
.
Default version does not fill, GitBook
use the latest version (compatible version) plug-ins.
Install plug
- If this is the official website of the online environment, the site will automatically help you install the plugin.
- If it is in the local environment, directly run
gitbook install
to install the plug-in.
$ gitbook install
Or use the npm
advance to download plug-ins to install to a local project :
$ npm install gitbook-plugin-<name>
$ gitbook install
Configure the plugin
Configure the plug-in book.json
configuration file pluginsConfig
property (if the property is not your own creation),
when installed plug-ins, the best browser plug-in documentation for more information about the options.
{
"plugins": ["github"],
"pluginsConfig": {
"github": {
"url": "https://github.com/snowdreams1006/snowdreams1006.github.io"
}
}
}
Some plug-ins do not provide plug-in configuration items, this step can be omitted, and some plug-in provides configuration items to plug presentations document shall prevail.
How to develop plug-ins
GitBook
Plug-in is npm
posted on follow the traditional definition of the node
package, in addition to the standard node
external norms there are some Gitbook
self-defined by the relevant norms.
Directory Structure
Gitbook
The most basic item plug structure comprising at least profile package.json
and entry files index.js
, other directory file itself changes in accordance with the use of plug-ins.
.
├── index.js
└── package.json
The actual plug-in project is slightly different, there may be
_layouts
the layout of directories,asset
resource directories and customexample
examples, anddocs
documentation directories, and so on.
package.json
package.json
Is the nodejs
configuration file, Gitbook
the plug also follow the specification, configuration file declares version descriptive information, in addition to plug-in Gitbook
related fields, follow the schema
guidelines basic example is as follows:
{
"name": "gitbook-plugin-mytest",
"version": "0.0.1",
"description": "This is my first GitBook plugin",
"engines": {
"gitbook": ">1.x.x"
},
"gitbook": {
"properties": {
"myConfigKey": {
"type": "string",
"default": "it's the default value",
"description": "It defines my awesome config!"
}
}
}
}
It is noteworthy that, the package name must
gitbook-plugin-
begin with, packet engine should be includedgitbook
. Forpackage.json
specifications, refer to the official documentation
index.js
index.js
It is an inlet plug runtime basic example as follows:
module.exports = {
// 钩子函数
hooks: {},
// 代码块
blocks: {},
// 过滤器
filters: {}
};
Release plug
GitBook
Plug-in npmjs
's official website posted on.
To release the plug, you first need in npmjs
the official website of the registered account , then issue the command line.
$ npm publish
Special plug-ins
Special plug-ins can be hosted GitHub
on, and use git
urls:
{
"plugins": [
"myplugin@git+https://github.com/MyCompany/mygitbookplugin.git#1.0.0"
]
}
Local test plug-in
Use npm link
can test your plug-in before the release, the command reference details of official documents
Plug-in file folders, run:
$ npm link
Then execute your book or document file folder:
$ npm link gitbook-plugin-<name>
Unit testing plug
gitbook-tester
You can easily write plugins Node.js / Mocha unit tests.
Use Travis
can submit / tag for each test run.
Plug summary
Gitbook
Plug-in is an extension of Gitbook
prime function of the election, if familiar with the nodejs
development process of the project, as long as the slightly familiar Gitbook
interface documentation provided to develop their own plug-ins should not be difficult!
Hopefully this article to your understanding of Gitbook
plug-in help, understand and master the whole process of plug-in development, if this article help you, do not forget to give me a positive feedback to encourage me to continue to create yo!
Reading extended
If this article help you, please tap the touch of hands is recommended , otherwise also correct me please leave a message and, if necessary, public awareness of personal numbers, " Snow Dream Inn technology ."