diff options
author | Doge <[email protected]> | 2021-05-08 01:20:50 +0800 |
---|---|---|
committer | Doge <[email protected]> | 2021-05-08 01:20:50 +0800 |
commit | e93cc42f9225f22094a19746f01f5cca99eeba1f (patch) | |
tree | c47a0e69e055ca0436dc9f36c460b5825601111d /scripts | |
parent | 8d17e308c8b43f12e11ed6b5a82f81e8dbcdd259 (diff) | |
download | chromate-e93cc42f9225f22094a19746f01f5cca99eeba1f.tar.gz chromate-e93cc42f9225f22094a19746f01f5cca99eeba1f.tar.bz2 chromate-e93cc42f9225f22094a19746f01f5cca99eeba1f.zip |
Add full lazyload support
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lazyload.js | 11 |
1 files changed, 11 insertions, 0 deletions
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(/<img(.*?)src="(.*?)"(.*?)>/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 |