mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-06-06 05:11:45 +08:00
This commit is contained in:
@@ -3,18 +3,19 @@
|
||||
* lazyload
|
||||
* replace src to data-src
|
||||
*/
|
||||
// <figure .+class="[^"]* highlight [^"]*".+>
|
||||
|
||||
'use strict'
|
||||
|
||||
const urlFor = require('hexo-util').url_for.bind(hexo)
|
||||
|
||||
function lazyProcess (htmlContent) {
|
||||
var bg = hexo.theme.config.lodding_bg.post ? urlFor(hexo.theme.config.lodding_bg.post) : 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs='
|
||||
return htmlContent.replace(/(<img .*?src=)/ig, `$1 ${bg} data-src=`)
|
||||
var 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-src=`)
|
||||
}
|
||||
|
||||
var processPost = function (data) {
|
||||
if (!hexo.theme.config.lazyload) return
|
||||
if (!hexo.theme.config.lazyload.enable) return
|
||||
data.content = lazyProcess.call(this, data.content)
|
||||
return data
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user