Hexo 拥有强大的插件系统,无需修改核心模块源代码,即可轻松扩展功能。Hexo 中有两种插件:
¥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
如果你的插件相对简单,建议使用脚本。你需要做的就是将你的 JavaScript 文件放在 scripts
文件夹中,Hexo 将在初始化期间加载它们。
¥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
如果你的代码很复杂或者你想将其发布到 NPM 注册表,我们建议使用插件。首先,在 node_modules
文件夹中创建一个文件夹。此文件夹的名称必须以 hexo-
开头,否则 Hexo 会忽略它。
¥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.
你的新文件夹必须包含至少两个文件:一个包含实际的 JavaScript 代码和一个 package.json
文件,该文件描述插件的用途并设置其依赖。
¥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.
. |
至少,你应该在 package.json
中设置 name
、version
和 main
条目。例如:
¥At the very least, you should set the name
, version
and main
entries in package.json
. For example:
{ |
你还需要将插件列为 hexo 实例根 package.json
中的依赖,以便 Hexo 检测并加载它。
¥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
你可以使用 Hexo 提供的官方工具来加速开发:
¥You can make use of the official tools provided by Hexo to accelerate development:
hexo-fs:文件 IO
¥hexo-fs:File IO
hexo-util:实用程序
¥hexo-util:Utilities
hexo-i18n:本地化 (i18n)
¥hexo-i18n:Localization (i18n)
hexo-pagination:生成分页数据
¥hexo-pagination:Generate pagination data
发布
¥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.
Fork hexojs/site
将存储库克隆到你的计算机并安装依赖。
¥Clone the repository to your computer and install dependencies.
git clone https://github.com/<username>/site.git
cd site
npm install在
source/_data/plugins/
中创建一个新的 yaml 文件,使用你的插件名称作为文件名¥Create a new yaml file in
source/_data/plugins/
, use your plugin name as the file name编辑
source/_data/plugins/<your-plugin-name>.yml
并添加你的插件。例如:¥Edit
source/_data/plugins/<your-plugin-name>.yml
and add your plugin. For example:description: Server module for Hexo.
link: https://github.com/hexojs/hexo-server
tags:
- official
- server
- console推送分支。
¥Push the branch.
创建一个拉取请求并描述更改。
¥Create a pull request and describe the change.