fix: preserve self-closing images in native lazyload

This commit is contained in:
if-else
2026-08-09 17:41:33 +08:00 Unverified
parent 51d36ef83a
commit 6d739e818a
+1 -1
View File
@@ -12,7 +12,7 @@ const lazyload = htmlContent => {
if (hexo.theme.config.lazyload.native) {
// 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 match.replace(/>$/, ' loading=\'lazy\'>')
return match.replace(/(\s*\/?)>$/, (_, closing) => ` loading='lazy'${closing}>`)
})
}