Tag

  • 2018-12-03

A tag allows users to quickly and easily insert snippets into their posts.

Synopsis

1
2
3
hexo.extend.tag.register(name, function(args, content){
// ...
}, options);

Two arguments will be passed into the tag function: args and content. args contains the arguments passed into the tag plugin and content is the wrapped content from the tag plugin.

Since the introduction of asynchronous rendering in Hexo 3, we are using Nunjucks for rendering. The behavior may be somewhat different from that in Swig.

Options

ends

Use end tags. This option is false by default.

async

Enable async mode. This option is false by default.

Examples

Without End Tags

Insert a Youtube video.

1
2
3
4
hexo.extend.tag.register('youtube', function(args){
var id = args[0];
return '<div class="video-container"><iframe width="560" height="315" src="http://www.youtube.com/embed/' + id + '" frameborder="0" allowfullscreen></iframe></div>';
});

With End Tags

Insert a pull quote.

1
2
3
4
hexo.extend.tag.register('pullquote', function(args, content){
var className = args.join(' ');
return '<blockquote class="pullquote' + className + '">' + content + '</blockquote>';
}, {ends: true});

Async Rendering

Insert a file.

1
2
3
4
5
6
7
8
9
10
11
var fs = require('hexo-fs');
var pathFn = require('path');

hexo.extend.tag.register('include_code', function(args){
var filename = args[0];
var path = pathFn.join(hexo.source_dir, filename);

return fs.readFile(path).then(function(content){
return '<pre><code>' + content + '</code></pre>';
});
}, {async: true});

扫码领红包

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

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

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

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

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