引言
Hexo 有强大的插件系统,使您能轻松扩展功能而不用修改核心模块的源码。在 Hexo 中有两种形式的插件:
脚本(Scripts)
如果您的代码很简单,建议您编写脚本,您只需要把 JavaScript 文件放到 scripts 文件夹,在启动时就会自动载入。
插件(Packages)
如果您的代码较复杂,或是您想要发布到 NPM 上,建议您编写插件。首先,在 node_modules 文件夹中建立文件夹,文件夹名称开头必须为 hexo-,如此一来 Hexo 才会在启动时载入否则 Hexo 将会忽略它。
以上引用来自hexo官方文档。所以,辅助函数也是hexo插件中的一种。除了辅助函数,还有以下类型的插件:
- 控制台 (Console)
- 部署器 (Deployer)
- 过滤器 (Filter)
- 生成器 (Generator)
- 迁移器 (Migrator)
- 处理器 (Processor)
- 渲染引擎 (Renderer)
- 标签 (Tag)
Hexo插件加载流程
首先上代码(hexo/lib/index.js):
Hexo.prototype.init = function() {
var self = this;
this.log.debug('Hexo version: %s', chalk.magenta(this.version));
this.log.debug('Working directory: %s', chalk.magenta(tildify(this.base_dir)));
// Load internal plugins
require('../plugins/console')(this);
require('../plugins/filter')(this);
require('../plugins/generator')(this);
require('../plugins/helper')(this);
require('../plugins/processor')(this);