控制台

控制台构成了 Hexo 与其用户之间的桥梁。它注册并描述可用的控制台命令。

¥The console forms the bridge between Hexo and its users. It registers and describes the available console commands.

概要

¥Synopsis

hexo.extend.console.register(name, desc, options, function (args) {
// ...
});
参数 描述
name 名称
desc 描述
options 选项

参数 args 将传递到函数中。这是用户在终端中输入的参数。由 Minimist 解析。

¥An argument args will be passed into the function. This is the argument that users type into the terminal. It’s parsed by Minimist.

选项

¥Options

usage

控制台命令的用法。例如:

¥The usage of a console command. For example:

{
usage: "[layout] <title>";
}
// hexo new [layout] <title>

arguments

控制台命令的每个参数的描述。例如:

¥The description of each argument of a console command. For example:

{
arguments: [
{ name: "layout", desc: "Post layout" },
{ name: "title", desc: "Post title" },
];
}

options

控制台命令的每个选项的描述。例如:

¥The description of each option of a console command. For example:

{
options: [{ name: "-r, --replace", desc: "Replace existing files" }];
}

desc

有关控制台命令的更多详细信息。

¥More detailed information about a console command.

示例

¥Example

hexo.extend.console.register(
"config",
"Display configuration",
function (args) {
console.log(hexo.config);
},
);