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}>`) }) }