Plugins

  • 2018-12-03

Hexo has a powerful plugin system, which makes it easy to extend functions without modifying the source code of the core module. There are two kinds of plugins in Hexo:

Script

If your plugin is relatively simple, it’s recommended to use a script. All you need to do is put your JavaScript files in the scripts folder and Hexo will load them during initialization.

Plugin

If your code is complicated or if you want to publish it to the NPM registry, we recommend using a plugin. First, create a folder in the node_modules folder. The name of this folder must begin with hexo- or Hexo will ignore it.

Your new folder must contain at least two files: one containing the actual JavaScript code and one package.json file that describes the purpose of the plugin and sets its dependencies.

1
2
3
.
├── index.js
└── package.json

At the very least, you should set the name, version and main entries in package.json. For example:

package.json
1
2
3
4
5
{
"name": "hexo-my-plugin",
"version": "0.0.1",
"main": "index"
}

You’ll also need to list your plugin as a dependency in the root package.json of your hexo instance in order for Hexo to detect and load it.

Tools

You can make use of the official tools provided by Hexo to accelerate development:

Publishing

When your plugin is ready, you may consider publishing it to the plugin list to invite other people to start using it. Publishing your own plugins is very similar to updating documentation.

  1. Fork hexojs/site
  2. Clone the repository to your computer and install dependencies.

    1
    2
    3
    $ git clone https://github.com/<username>/site.git
    $ cd site
    $ npm install
  3. Edit source/_data/plugins.yml and add your plugin. For example:

    1
    2
    3
    4
    5
    6
    7
    - name: hexo-server
    description: Server module for Hexo.
    link: https://github.com/hexojs/hexo-server
    tags:
    - official
    - server
    - console
  4. Push the branch.

  5. Create a pull request and describe the change.

扫码领红包

2018双11超级红包
PC访问链接: 2018双11超级红包 预售开启 汇聚全球潮流新品

淘口令:¥20Y0b6q4eHR¥ (复制此行再打开手机淘宝客访问)

最后更新: 2018年12月03日 09:29

原始链接: https://cyc.oy99.com/docs/plugins.html

× 多少都行~
打赏二维码
×
  • {title}