fix: fixed lazyload not working when `alt` attribute is empty
This commit is contained in:
parent
41e59293cb
commit
002374b304
|
@ -11,9 +11,12 @@ hexo.extend.filter.register(
|
|||
// Match 'img' tags the src attribute.
|
||||
/<img([^>]*)src="([^"]*)"([^>\/]*)\/?\s*>/gim,
|
||||
function (match, attrBegin, src, attrEnd) {
|
||||
let hasAlt = false
|
||||
if (!src) return match
|
||||
;[attrBegin, attrEnd].forEach(x => { if (x.includes('alt="')) { hasAlt = true } })
|
||||
return `<img ${attrBegin}
|
||||
lazyload
|
||||
${hasAlt ? '' : 'alt="image"'}
|
||||
data-src="${src}"
|
||||
${attrEnd}
|
||||
>`
|
||||
|
|
Loading…
Reference in New Issue