-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec70baa
commit eac8d8f
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |