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.
|
// Match 'img' tags the src attribute.
|
||||||
/<img([^>]*)src="([^"]*)"([^>\/]*)\/?\s*>/gim,
|
/<img([^>]*)src="([^"]*)"([^>\/]*)\/?\s*>/gim,
|
||||||
function (match, attrBegin, src, attrEnd) {
|
function (match, attrBegin, src, attrEnd) {
|
||||||
|
let hasAlt = false
|
||||||
if (!src) return match
|
if (!src) return match
|
||||||
|
;[attrBegin, attrEnd].forEach(x => { if (x.includes('alt="')) { hasAlt = true } })
|
||||||
return `<img ${attrBegin}
|
return `<img ${attrBegin}
|
||||||
lazyload
|
lazyload
|
||||||
|
${hasAlt ? '' : 'alt="image"'}
|
||||||
data-src="${src}"
|
data-src="${src}"
|
||||||
${attrEnd}
|
${attrEnd}
|
||||||
>`
|
>`
|
||||||
|
|
Loading…
Reference in New Issue