summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDoge <[email protected]>2021-05-08 01:20:50 +0800
committerDoge <[email protected]>2021-05-08 01:20:50 +0800
commite93cc42f9225f22094a19746f01f5cca99eeba1f (patch)
treec47a0e69e055ca0436dc9f36c460b5825601111d /scripts
parent8d17e308c8b43f12e11ed6b5a82f81e8dbcdd259 (diff)
downloadchromate-e93cc42f9225f22094a19746f01f5cca99eeba1f.tar.gz
chromate-e93cc42f9225f22094a19746f01f5cca99eeba1f.tar.bz2
chromate-e93cc42f9225f22094a19746f01f5cca99eeba1f.zip
Add full lazyload support
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lazyload.js11
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