mirror of https://github.com/jkjoy/sunpeiwen.git
22 lines
627 B
JavaScript
22 lines
627 B
JavaScript
/**
|
|
* lazyload.js
|
|
* transplant from hexo-theme-butterfly
|
|
*/
|
|
|
|
'use strict'
|
|
|
|
const urlFor = require('hexo-util').url_for.bind(hexo)
|
|
|
|
function lazyProcess (htmlContent) {
|
|
var bg = hexo.theme.config.lazyload.image ? urlFor(hexo.theme.config.lazyload.image) : 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs='
|
|
return htmlContent.replace(/(<img .*?src=)/ig, `$1 "${bg}" data-src=`)
|
|
}
|
|
|
|
var processPost = function (data) {
|
|
if (!hexo.theme.config.lazyload.enable) return
|
|
data.content = lazyProcess.call(this, data.content)
|
|
return data
|
|
}
|
|
|
|
hexo.extend.filter.register('after_post_render', processPost)
|