ルーター

ルーターはサイトで使用されるすべてのパスを保存します。

パスの取得

getメソッドはStreamを返却します。たとえば、指定された宛先にパスデータを保存するには:

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

data.pipe(dest);

パスの設定

setメソッドは文字列、Buffer、または関数を引数に取ります。

// 文字列
hexo.route.set('index.html', 'index')

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

// 関数 (Promise)
hexo.route.set('index.html', function(){
return new Promise(function(resolve, reject){
resolve('index');
});
});

// 関数 (コールバック)
hexo.route.set('index.html', function(callback){
callback(null, 'index');
});

パスが変更されたかどうかのブール値も設定できます。これにより、変更されていないファイルを無視することでファイル生成を高速化できます。

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