mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-08-10 20:48:42 +08:00
fix: preserve self-closing images in native lazyload
This commit is contained in:
@@ -12,7 +12,7 @@ const lazyload = htmlContent => {
|
|||||||
if (hexo.theme.config.lazyload.native) {
|
if (hexo.theme.config.lazyload.native) {
|
||||||
// Use more precise replacement: only replace img tags in HTML, not content inside script tags
|
// Use more precise replacement: only replace img tags in HTML, not content inside script tags
|
||||||
return htmlContent.replace(/(<img(?![^>]*?\bloading=)(?:\s[^>]*?)?>)(?![^<]*<\/script>)/gi, match => {
|
return htmlContent.replace(/(<img(?![^>]*?\bloading=)(?:\s[^>]*?)?>)(?![^<]*<\/script>)/gi, match => {
|
||||||
return match.replace(/>$/, ' loading=\'lazy\'>')
|
return match.replace(/(\s*\/?)>$/, (_, closing) => ` loading='lazy'${closing}>`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user