From e93cc42f9225f22094a19746f01f5cca99eeba1f Mon Sep 17 00:00:00 2001 From: Doge Date: Sat, 8 May 2021 01:20:50 +0800 Subject: Add full lazyload support --- scripts/lazyload.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 scripts/lazyload.js (limited to 'scripts') diff --git a/scripts/lazyload.js b/scripts/lazyload.js new file mode 100644 index 0000000..edacbbb --- /dev/null +++ b/scripts/lazyload.js @@ -0,0 +1,11 @@ +'use strict'; + +hexo.extend.filter.register('after_post_render', (data) => { + if (hexo.theme.config.lazyload !== true) return; + const loading = "data:image/gif;base64,R0lGODlhAQABAAAAACw="; + data.content = data.content.replace(//gi, (str, _, src) => { + if (/data-srcset/gi.test(str) || /src="data:image(.*?)/gi.test(str)) + return str; + return str.replace(src, `${src}" class="lazy" data-srcset="${src}" srcset="${loading}`); + }); +}); \ No newline at end of file -- cgit v1.2.3