Skip to content

Commit

Permalink
feat: show number of images imported
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Jul 25, 2020
1 parent c3b2ec0 commit ae9c3da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = async function(args) {
let untitledPostCounter = 0;
let errNum = 0;
let skipNum = 0;
let imgNum = 0;
let input, feed;
const rExcerpt = /<!--+\s*more\s*--+>/i;
const postExcerpt = '\n<!-- more -->\n';
Expand Down Expand Up @@ -106,6 +107,7 @@ module.exports = async function(args) {
}

images[image_url] = imagePath;
imgNum++;
} catch (err) {
log.e(err);
}
Expand Down Expand Up @@ -213,6 +215,7 @@ module.exports = async function(args) {
log.w('%d posts did not have titles and were prefixed with "Untitled Post".', untitledPostCounter);
}
if (postsNum) log.i('%d posts migrated.', postsNum);
if (imgNum) log.i('%d images migrated.', imgNum);
if (errNum) log.error('%d posts failed to migrate.', posts.length);
if (skipNum) log.i('%d posts skipped.', skipNum);
}
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ describe('migrator', function() {

log.i.calledWith('Image found: %s', imagePath).should.eql(true);

const { items } = await parseFeed(xml);
const imgNum = items.filter(({type}) => type === 'attachment').length;
const { lastCall } = log.i;
lastCall.calledWith('%d images migrated.', imgNum).should.eql(true);

const image = await readFile(join(hexo.source_dir, imagePath), { encoding: 'binary' });
const header = Buffer.from(image, 'binary').toString('hex').substring(0, 14);

Expand Down

0 comments on commit ae9c3da

Please sign in to comment.