Renderer

  • 2018-12-03

A renderer is used to render content.

Synopsis

1
2
3
hexo.extend.renderer.register(name, output, function(data, options){
// ...
}, sync);
Argument Description
name Input filename extension (lower case, without leading .)
output Output filename extension (lower case, without leading .)
sync Sync mode

Two arguments will be passed into the render function:

Argument Description
data Include two attributes: file path path and file content text. path won’t necessarily exist.
option Options

Example

Async Mode

1
2
3
4
5
6
7
8
9
10
11
12
13
var stylus = require('stylus');

// Callback
hexo.extend.renderer.register('styl', 'css', function(data, options, callback){
stylus(data.text).set('filename', data.path).render(callback);
});

// Promise
hexo.extend.renderer.register('styl', 'css', function(data, options){
return new Promise(function(resolve, reject){
resolve('test');
});
});

Sync Mode

1
2
3
4
5
6
var ejs = require('ejs');

hexo.extend.renderer.register('ejs', 'html', function(data, options){
options.filename = data.path;
return ejs.render(data.text, options);
}, true);

扫码领红包

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

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

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

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

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