What is a plug-in

Gitbook plug-in is the best way to expand the function of Gitbook, if Gitbook does not have the desired function or there is no ready-made solution on the network, then the only way left to live on their own, let’s develop plug-ins to solve the problem together!

Fortunately,Gitbook provides a plugin mechanism for developers to extend custom features. The official development documentation is not perfect, and sometimes you need to consult the source code to locate exposed apis, but that doesn’t stop us from developing Gitbook in the first place.

Unfortunately, Gitbook has stopped the old version of the service, and gitbook-CLI scaffolding has even stopped the maintenance, but I still love lightweight scaffolding, do not give up, so I spent some effort to sort out the relevant documents.

  • gitbookThe official documentation

“Snow dream technology station” : Gitbook official document transplantation project, including the original English and calibrated Chinese, welcome to join the maintenance!

  • gitbookIntroductory tutorial

“Snow dream technology station” : from entry to skilled use of a series of articles, advanced chapter detailed introduction to the basic knowledge of plug-in development, easy to understand all dry goods!

  • mygitalkComment on the plug-in

“Snow dream technology station” : Based on gitalk implementation of Gitbook plug-in, detailed introduction from the idea to the implementation of the whole process, secondary packaging third-party tools worth learning.

  • readmoreRead more plugins

“Snow dream technology station” : readMore based on the implementation of readMore plug-in, based on template rendering means encapsulation of third-party tools, and mygitalk plug-in implementation ideas complement each other!

Why do plugins

“Snow dream technology station” : because there is no ready-made plug-in, so self-reliance, because the force and so open source!

If you and I publish articles on the whole platform, it is estimated that you will also encounter the same problem as ME: original first personal blog reprinted from other major platforms, in order to attract traffic always have to add the original statement small tail, trouble and trouble!

When this kind of meaningless labor is repeated again and again, nature should seek a solution, lazy is the original power to promote the development of productivity!

Now it’s clear that we need to develop a Gitbook plug-in to help articles automatically add copyright protection information to reduce human labor.

Fortunately, moOCs and CSDN come with their own copyright protection on every major platform you visit, so you might as well join forces to develop an enhanced version of the copyright protection plug-in.

  • Moocs copyright Notice
Author: snow dream technology post links: https://www.imooc.com/article/293112 source: for classCopy the code

“Snow dream technology station” : MoOCs notes will automatically add copyright protection information when copying content, including author, link and source.

  • CSDN Copyright Notice
Copyright notice: This article is originally published BY the blogger. It follows the COPYRIGHT agreement CC 4.0 BY-SA. Please attach the link of the original source and this statement. This paper links: https://snowdreams1006.blog.csdn.net/article/details/102077796 -- -- -- -- -- -- -- -- copyright statement: This article is originally published BY CSDN blogger "Snow Dream Technology Station". It follows CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement. The original link: https://snowdreams1006.blog.csdn.net/article/details/102077796Copy the code

“Snow Dream Technology Station” : CSDN will automatically add the copyright statement information at the beginning of the original blog, including the copyright statement and the article chain. The copyright protection information will be added when the copyright information is copied.

  • Strong joint copyright protection plug-in declaration

Copyright protection information will be added to copy the full text of MOOCs notebook articles, and the copyright protection information will be added only when the copyright information is copied at the beginning of CSDN original blog. Combining the two, we might as well make an enhanced version of copyright protection plug-in.

Author: the dream of snow technical post links: https://snowdreams1006.github.io/myGitbook/advance/plugin-develop.html sources: Snow dream technology station this article was originally published in the snow dream technology station, reprint please note the source, thank you cooperation!Copy the code

“Snow dream technology station” : copyright information will be automatically added at the end of the article, and copyright protection information will be automatically added when copying any article content.

How to make plug-ins quickly

According to the implementation effect of the plug-in, we will temporarily name the plug-in copyright plug-in, the next is to quickly public registration plug-in to avoid the name is first!

“Snow dream technology station” : temporarily not in a hurry to realize the role of plug-ins, preempt the opportunity is very important, small steps quickly run to register plug-ins!

  • npmjs websiteOnline registration

“Snow dream technology station” : the registration process is relatively simple, the user name and email and other information can be released without paying.

  • Command line operationnpm adduserregistered
$ npm adduser
Copy the code

“Snow dream technology station” : the terminal registration is basically the same as the web version registration, requiring user name, password and email.

Querying the plug-in name

According to the Gitbook plug-in naming convention, utility plug-ins must begin with gitbook-plugin-*, and our plug-in is called copyright because the full name should be Gitbook-plugin-copyright.

  • The plug-in name is searched by keyword in the command line
$ npm search --keyword gitbook-plugin-copyright
Copy the code

“Snow dream technology station” : if you did not find the project, congratulations, the name is available, hurry up and register! Otherwise, rename until available!

  • NPMJS is an online search for the name of the plugin

Search by keyword: www.npmjs.com/search?q=gi…

“Snow dream technology station” : if there is no exact match, congratulations, the name is available, please register the plug-in as soon as possible. Otherwise, create a new name until the name is available!

Create open Source projects

After confirming that the plug-in name is temporarily available after the previous query, you should immediately go to Github to create an open source project with the same name as the plug-in for subsequent update and maintenance.

  • Create open Source projects

“Snow dream technology station” : when creating plug-in projects, it is recommended to complete the project information as much as possible, add README files and copyright types.

  • Clone to local project

“Snow dream technology station” : click the clone or download button to obtain the clone link, ready to download to the local development of the plug-in project.

$ git clone [email protected]:snowdreams1006/gitbook-plugin-copyright.git
Copy the code
  • Initialize the NPMJS project

After cloning to the local workspace, switch to the plug-in project directory and run the initialization NPM project command to generate the default package.json configuration file.

$ npm init -y
Copy the code

“Snow dream technology station” : the default information is basically enough, do not need to modify, the key is to quickly preempt the plug-in name!

  • Publish the NPMJS project
$ npm publish
Copy the code

“Snow dream technology post” : release NPMJS NPM package should login account login, and is set to NPMJS official image source, NPM set registry at https://registry.npmjs.org/.

Successful squatting plug-in

If you run the NPM publish command on the command line and there is no error, congratulations! Plug-ins should be successfully published to the NPMJS package registry!

  • Verify that the plug-in was successfully published

If there are no errors on the command line when you publish a plug-in, you should be able to find the plug-in you just published, either on the command line or on your website.

$ npm search --keyword gitbook-plugin-copyright
Copy the code

“Snow dream tech station” : run NPM search –keyword gitbook-plugin-copyright again in command line to find the plugin has been successfully registered!

“Snow dream technology station” : the name of the plug-in searched is just released successfully, at this time the name of the plug-in gitbook-plugin-copyright has been successfully registered!

Click the name of the plug-in to jump to the plug-in introduction page, the basic framework has begun to take shape, the next work is the real plug-in development.

“Snow dream technology station” : At this point the plugin has been successfully published to the NPMJS package management center, anyone can install the plugin using NPM install gitbook-plugin-Copyright, but there is no code logic for the time being!

Now that the plug-in has been published to the NPMJS package management tool, the source code has not been uploaded to a remote server for further open source maintenance, so create a milestone to mark a memorable moment and prepare to sync to Github.

  • First, create locallyv0.0.1version
$git tag v0.0.1-m"init"
Copy the code
  • It is then pushed to the remote server
$git push Origin v0.0.1Copy the code

Download: github.com/snowdreams1…

  • Finally, update the trunkmasterbranch
$ git push origin master
Copy the code

At this point, the whole process from creating plug-ins to publishing plug-ins and finally synchronizing the source code of plug-ins is basically completed, and developing plug-ins and publishing them from zero to one is so simple!

Relevant summary and preview

This article mainly shows you how to publish your plug-in from 0 to 1. It’s just a skeleton, no specific code, but it’s enough for the full development process!

You won’t be developing the same Gitbook-plugin-Copyright plugin over and over again, so the code may not be particularly useful to the reader.

But as we’ve learned in this article, it’s not that hard to develop plug-ins!

Most of the problems in development are basically solved on the web. You just need to learn how to search and have some learning ability, and you will eventually be able to develop your own plug-in.

NPMJS related commands

  • Registered account
$ npm adduser
Copy the code

“Snow dream technology station” : the command line registration information is relatively simple, not as good as the web version of the registration can also set up a profile picture, the web version of the registration is recommended.

  • Login account
$ npm login
Copy the code

“Snow dream technology station” : regardless of which registration method, before publishing plug-ins, you must log in to confirm the information of the plug-in author.

  • Viewing the Current User
$ npm whoami
Copy the code

“Snow dream technology post station” : after logging in explicitly, you must know that you have logged in just now. After some time, can you remember who logged in? In this case, you can run this command to view information about the current login user.

  • Create NPMJS package
$ npm init -y
Copy the code

“Snow dream Technology Station” : The configuration file package.json created by default is sufficient. You can modify the related configuration information by yourself.

  • Switch the official NPMJS image source
$ npm set registry https://registry.npmjs.org/
Copy the code

“Snow dream technology station” : forcibly switch to the official mirror source, mainly for users who may use taobao mirror source.

  • Release NPMJS package
$ npm publish
Copy the code

“Snow dream technology station” : please ensure that you have logged in and switched to the official mirror source before releasing the plug-in, otherwise the press conference will fail!

  • Search NPMJS packages by keyword
$ npm search --keyword gitbook-plugin-<package>
Copy the code

“Snow dream technology station” : before the release is not registered, the search results, after the release of the plug-in author information should be the current user.

Git git

  • Clone to local project
$ git clone [email protected]:<username>/gitbook-plugin-<package>.git
Copy the code
  • Commit changes to the local version library
$ git commit -am "change log"
Copy the code
  • Create a local label version
$ git tag <version> -m "publish log"
Copy the code
  • Push labels to remote servers
$ git push origin <version>
Copy the code
  • Push the latest code to the remote trunkmaster
$ git push origin master
Copy the code

If you have any good ideas or ideas, hurry to register, after all, the name is the only global unique ah!

In the next section we’ll start to show you how to breathe life into the basic skeleton, make it a true Gitbook plug-in, and even implement the Gitbook-plugin-Copyright plug-in functionality!

Open source project: github.com/snowdreams1…

If you feel that this article is helpful to you, welcome to like the message to tell me, your encouragement is my motivation to continue to create, might as well pay attention to the personal public number “snow dream technology station”, regularly update quality articles!