This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
mystic/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;
});