🎨 代碼優化

This commit is contained in:
Jerry
2020-07-27 16:48:41 +08:00
Unverified
parent d2943bbbb1
commit f4f725bb93
10 changed files with 76 additions and 90 deletions
+4 -11
View File
@@ -8,15 +8,8 @@
const urlFor = require('hexo-util').url_for.bind(hexo)
function lazyProcess (htmlContent) {
const bg = hexo.theme.config.lazyload.post ? urlFor(hexo.theme.config.lazyload.post) : 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs='
return htmlContent.replace(/(<img.*? src=)/ig, `$1 "${bg}" data-lazy-src=`)
}
const processPost = function (data) {
hexo.extend.filter.register('after_post_render', 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)
const bg = hexo.theme.config.lazyload.post ? urlFor(hexo.theme.config.lazyload.post) : 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs='
return data.content.replace(/(<img.*? src=)/ig, `$1 "${bg}" data-lazy-src=`)
})