Update process.js

This commit is contained in:
谷風天音 | 是一个浓度纯度都比较高的柚子厨,因为柚子社天下第一!时不时发柚子的癫。有个能干的妹妹真好,たにかぜ あまね天下第一喵,关注谷風天音谢谢喵,关注谷風天音谢谢喵,谢谢在这里看我发癫,天音妹妹真的好好看喵,单推天音一辈子!谁不推天音就打爆他的宁宁的起爆器!\柚子社/\柚子社/\柚子社/\天音/\天音/\天音/天音,我真的好喜欢你啊,为了你,我要 0721!\たにかぜ あまね/\たにかぜ あまね/\たにかぜ あまね/\たにかぜ あまね/\たにかぜ あまね/\たにかぜ あまね/\たにかぜ あまね/ 2023-02-12 09:31:40 +08:00 committed by GitHub
parent f64dd66736
commit c2939e4db2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 8 deletions

View File

@ -1,15 +1,18 @@
'use strict';
const fs = require('hexo-fs');
function lazyProcess(htmlContent) {
let loadingImage = this.config.lazyload.loadingImg || 'https://img-blog.csdnimg.cn/2022010612032038329.gif';
return htmlContent.replace(/<img(\s*?)src="(.*?)"(.*?)>/gi, (str, p1, p2, p3) => {
function lazyProcess(htmlContent) {
let loadingImage = this.config.lazyload.loadingImg || 'https://cdn.jsdelivr.net/skx@0.0.9/img/lazy.gif';
return htmlContent.replace(/<img(\s*?)src="(.*?)"(.*?)>/gi, (str, p1, p2, p3) => {
if (/data-src/gi.test(str)) {
return str;
}
return `<img${p1} srcset="${loadingImage}" data-srcset="${p2}" class="lazyload"${p3}>`;
if (/class="(.*?)"/gi.test(str)){
str = str.replace(/class="(.*?)"/gi, (classStr, p1) => {
return classStr.replace(p1, `${p1} lazyload`);
})
return str.replace(p3, `${p3} srcset="${loadingImage}" data-srcset="${p2}"`);
}
return str.replace(p3, `${p3} class="lazyload" srcset="${loadingImage}" data-srcset="${p2}"`);
});
}
@ -18,6 +21,6 @@ module.exports.processPost = function(data) {
return data;
};
module.exports.processSite = function(htmlContent) {
module.exports.processSite = function (htmlContent) {
return lazyProcess.call(this, htmlContent);
};