summaryrefslogtreecommitdiff
path: root/scripts/lazyload.js
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lazyload.js')
-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