Router

  • 2018-12-03

The router saves all paths used in the site.

Get a Path

The get method returns a Stream. For example, to save the path data to a specified destination:

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

data.pipe(dest);

Set a Path

The set method takes a string, a Buffer or a function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 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.

1
2
3
4
5
6
hexo.route.set('index.html', {
data: 'index',
modified: false
});

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

Remove a Path

1
hexo.route.remove('index.html');

Get the List of Routes

1
hexo.route.list();

Format a Path

The format method transforms a string to a valid path.

1
2
hexo.route.format('archives/');
// archives/index.html

扫码领红包

2018双11超级红包
PC访问链接: 2018双11超级红包 预售开启 汇聚全球潮流新品

淘口令:¥20Y0b6q4eHR¥ (复制此行再打开手机淘宝客访问)

最后更新: 2018年12月03日 09:29

原始链接: https://cyc.oy99.com/api/router.html

× 多少都行~
打赏二维码
×
  • {title}