路由

  • 2018-12-03

路由儲存了網站中所用到的所有路徑。

取得路徑

get 方法會傳回一個 Stream,例如把該路徑的資料儲存到某個指定位置。

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

data.pipe(dest);

設定路徑

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

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');
});

您還可設定該路徑是否更新,這樣在生成檔案時便能忽略未更動的檔案,加快生成時間。

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

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

移除路徑

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

取得路由表

1
hexo.route.list();

格式化路徑

format 方法可將字串轉為合法的路徑。

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

扫码领红包

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

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

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

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

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