From 6d739e818ad2dfc900685bba4be040627892d86e Mon Sep 17 00:00:00 2001 From: if-else <135977013+Even-lwx@users.noreply.github.com> Date: Sun, 9 Aug 2026 17:41:33 +0800 Subject: [PATCH] fix: preserve self-closing images in native lazyload --- scripts/filters/post_lazyload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/filters/post_lazyload.js b/scripts/filters/post_lazyload.js index eec040a..1cbc8a2 100644 --- a/scripts/filters/post_lazyload.js +++ b/scripts/filters/post_lazyload.js @@ -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(/(]*?\bloading=)(?:\s[^>]*?)?>)(?![^<]*<\/script>)/gi, match => { - return match.replace(/>$/, ' loading=\'lazy\'>') + return match.replace(/(\s*\/?)>$/, (_, closing) => ` loading='lazy'${closing}>`) }) }