delete lazyload

This commit is contained in:
Nofated095 2023-12-31 16:35:46 +08:00
parent 0eb6d6401d
commit 529c67f6b2
4 changed files with 2 additions and 44 deletions

View File

@ -1,6 +1,6 @@
{
"name": "hexo-theme-amane",
"version": "0.0.40",
"version": "0.0.41",
"author": "Nofated095 <nofated095@users.noreply.github.com>",
"license": "MIT",
"description": "A simple, delicate, and modern theme for Hexo",

View File

@ -4,14 +4,7 @@ const logger = require('hexo-log')();
/**
* Print welcome message
*/
logger.info(`=======================================
=============================================`);
logger.info(`hexo-theme-amane`);
/**
* Check if all dependencies are installed

View File

@ -1,9 +0,0 @@
'use strict';
if (!hexo.config.lazyload || !hexo.config.lazyload.enable) {
return;
}
if (hexo.config.lazyload.onlypost) {
hexo.extend.filter.register('after_post_render', require('./lib/process').processPost);
} else {
hexo.extend.filter.register('after_render:html', require('./lib/process').processSite);
}

View File

@ -1,26 +0,0 @@
'use strict';
const fs = require('hexo-fs');
function lazyProcess(htmlContent) {
let loadingImage = this.config.lazyload.loadingImg || 'https://blog.amane.icu/lazyload.gif';
return htmlContent.replace(/<img(.*?)src="(.*?)"(.*?)>/gi, (str, p1, p2) => {
if (/data-src/gi.test(str)) {
return str;
}
if (/class="(.*?)"/gi.test(str)){
str = str.replace(/class="(.*?)"/gi, (classStr, p1) => {
return classStr.replace(p1, `${p1} lazy`);
})
return str.replace(`src="${p2}"`, `src="${p2}" class="lazy" data-srcset="${p2}" srcset="${loadingImage}"`);
}
return str.replace(`src="${p2}"`, `src="${p2}" class="lazy" data-srcset="${p2}" srcset="${loadingImage}"`);
});
}
module.exports.processPost = function(data) {
data.content = lazyProcess.call(this, data.content);
return data;
};
module.exports.processSite = function (htmlContent) {
return lazyProcess.call(this, htmlContent);
};