Skip to content

Commit

Permalink
register generate thumb event to before_exit & use async maplimit to …
Browse files Browse the repository at this point in the history
…20 concurrency
  • Loading branch information
Robin-front committed Mar 20, 2018
1 parent 8b3e99b commit 82383be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if (!lazyload || !lazyload.enable) {
return;
}

const concurrency = lazyload.concurrency || 20;
const loadingImgPath = lazyload.loadingImg || '/js/lazyload-plugin/loading.svg';
const thumbPath = lazyload.thumbPath || './images/thumb';
const thumbTargetFolder = path.resolve(hexo.base_dir, 'public/', thumbPath);
Expand Down Expand Up @@ -144,9 +145,10 @@ hexo.extend.filter.register('after_post_render', function (data) {
return data;
});

hexo.extend.filter.register('after_generate', async function loopPipe() {
log('start processing thumb');
return await async.mapLimit(waitForThumb, 5, async function (url) {
hexo.extend.filter.register('before_exit', async function loopPipe() {
if (!waitForThumb.length) { return false; }
log('start processing ' + waitForThumb.length +' thumb');
return await async.mapLimit(waitForThumb, concurrency, async function (url) {
const response = await generateThumb(url);
return response;
}, (err) => {
Expand All @@ -155,4 +157,4 @@ hexo.extend.filter.register('after_generate', async function loopPipe() {
// console.log('results', results)
log('All thumb process successed !');
});
});
}, 1);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-lazyload",
"version": "1.2.4",
"version": "1.2.5",
"description": "use IntersectionObserver api to improve lazyload performance",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 82383be

Please sign in to comment.