Skip to content

Instantly share code, notes, and snippets.

@itolssy
Created May 20, 2014 10:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itolssy/c7914e3a3913c767ed33 to your computer and use it in GitHub Desktop.
Save itolssy/c7914e3a3913c767ed33 to your computer and use it in GitHub Desktop.
Hexo extended tags
var render = hexo.render,
tag = hexo.extend.tag,
helper = hexo.extend.helper;
/**
* youku video tag
*
* Syntax:
* {% youku id %}
*/
var youku = function(args, content){
var id = args[0];
return '<div class="video-container"><iframe width="560" height="315" src="http://player.youku.com/embed/' + id + '" frameborder="0" allowfullscreen></iframe></div>';
};
/**
* tudou video tag
*
* Syntax:
* {% tudou id %}
*/
var tudou = function(args, content){
var id = args[0];
return '<div class="video-container"><iframe width="560" height="315" src="http://www.tudou.com/programs/view/html5embed.action?type=0&code=' + id + '" frameborder="0" allowfullscreen></iframe></div>';
};
/**
* margin note tag
*
* Syntax:
* {% mnote index %}
* Margin note string
* {% endmnote %}
*/
var mnote = function(args, content){
if (args){
var index = args[0];
mnote = '<span class="margin-note-marker"><sup>' + index + '</sup></span> <span class="block margin-div-outer"><span class="block margin-div-inner"><span class="margin-note"><span class="margin-note-marker">' + index + '</span>' + content + '</span></span></span>';
} else {
mnote = '<span class="block margin-div-outer"><span class="block margin-div-inner"><span class="margin-note">' + content + '</span></span></span>';
}
var text = render.renderSync({text: mnote, engine: 'markdown'});
text = text.substring(3, text.length-5);
return text;
};
/**
* margin image tag
*
* Syntax:
* {% mimg url text index %}
*/
var mimg = function(args, content){
var url = args[0];
var text = args[1];
var index = args[2];
return '<span class="block margin-div-outer"><span class="block margin-div-inner"><span class="block margin-note"><img src=' + url + ' alt="' + text + '" /><b>图' + index + '</b> ' + text + '</span></span></span>';
};
/**
* local file tag
*
* Syntax:
* {% attach file [path] %}
*/
var attach = function(args, content){
var fileName = args[0];
var path = args[1] || 'downloads';
var fullPath = hexo.config.root + path + '/' + fileName;
return '<a href="' + fullPath + '" download="' + fileName + '">' + fileName + '</a>'
}
tag.register('youku', youku, false);
tag.register('tudou', tudou, false);
tag.register('mnote', mnote, true);
tag.register('mimg', mimg, false);
tag.register('attach', attach, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment