Merge pull request #1822 from Even-lwx/fix/native-lazyload-self-closing-images

fix: preserve self-closing images in native lazyload
This commit is contained in:
Jerry Wong
2026-08-10 18:03:51 +08:00
committed by GitHub
Unverified
+1 -1
View File
@@ -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}>`)
}) })
} }