Skip to content

Commit

Permalink
ADD: lazyload image [2].
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-nginx authored May 28, 2017
1 parent ec70baa commit eac8d8f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scripts/tags/lazy-image
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* global hexo */
// Usage: {% lazyimage /path/to/image, alt, title %}
// Alias: {% li /path/to/image, alt, title %}

function lazyImage(args) {
args = args.join(' ').split(',');
var src = args[0];
var alt = args[1] || '';
var title = args[2] || '';

if (!src) {
hexo.log.warn('Image src can NOT be empty');
}
alt = alt.trim();
title = title.trim();

var image = ['<span itemprop="image" itemscope itemtype="http://schema.org/ImageObject"><img itemprop="url image" src="/images/loading.gif" data-original="' + src + '" class="full-image"'];
alt.length > 0 && image.push('alt="' + alt + '"');
title.length > 0 && image.push('title="' + title + '"');
image.push('/><meta itemprop="width" content="auto"><meta itemprop="height" content="auto"></span>');

return image.join(' ');
}

hexo.extend.tag.register('lazyimage', lazyImage);
hexo.extend.tag.register('li', lazyImage);

0 comments on commit eac8d8f

Please sign in to comment.