路由

路由存储了网站中所用到的所有路径。

获取路径

get 方法会传回一个 Stream。 例如,把该路径的数据存储到某个指定位置:

var data = hexo.route.get("index.html");
var dest = fs.createWriteStream("somewhere");

data.pipe(dest);

设置路径

您可以在 set 方法中使用字符串、Buffer 或函数,如下:

// String
hexo.route.set("index.html", "index");

// Buffer
hexo.route.set("index.html", new Buffer("index"));

// Function (Promise)
hexo.route.set("index.html", function () {
return new Promise(function (resolve, reject) {
resolve("index");
});
});

// Function (Callback)
hexo.route.set("index.html", function (callback) {
callback(null, "index");
});

You can also set a boolean for whether a path has been modified or not. This can speed up file generation as it allows for ignoring the unmodified files.

hexo.route.set("index.html", {
data: "index",
modified: false,
});

// hexo.route.isModified('index.html') => false

移除路径

hexo.route.remove("index.html");

获取路由列表

hexo.route.list();

格式化路径

format 方法可将字符串转为合法的路径。

hexo.route.format("archives/");
// archives/index.html