Update process.js
This commit is contained in:
parent
f64dd66736
commit
c2939e4db2
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue