The router saves all paths used in the site.
The get
method returns a Stream. For example, to save the path data to a specified destination:
var data = hexo.route.get('index.html');
var dest = fs.createWriteStream('somewhere');
data.pipe(dest);
The set
method takes a string, a Buffer or a function.
// 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();
The format
method transforms a string to a valid path.
hexo.route.format('archives/');
// archives/index.html