sbbs/themes/hueman/scripts/thumbnail.js

17 lines
460 B
JavaScript
Raw Normal View History

2018-09-03 07:41:16 +00:00
/**
* Thumbnail Helper
* @description Get the thumbnail url from a post
* @example
* <%- thumbnail(post) %>
*/
hexo.extend.helper.register('thumbnail', function (post) {
var url = post.thumbnail || '';
if (!url) {
var imgPattern = /\<img\s.*?\s?src\s*=\s*['|"]?([^\s'"]+).*?\>/ig;
var result = imgPattern.exec(post.content);
if (result && result.length > 1) {
url = result[1];
}
}
return url;
});