From faf0e5edff274c2a9569fe083285dbe922be8bbb Mon Sep 17 00:00:00 2001 From: JiJi Date: Wed, 10 Mar 2021 22:30:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9src=E5=B9=B6=E9=87=8D?= =?UTF-8?q?=E6=96=B0build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #15 --- lib/bangumi-generator.js | 30 ++++++++++++++++++++---------- src/lib/bangumi-generator.js | 20 +++++++++++++++++++- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/lib/bangumi-generator.js b/lib/bangumi-generator.js index 3ce4def..5df140a 100644 --- a/lib/bangumi-generator.js +++ b/lib/bangumi-generator.js @@ -23,7 +23,7 @@ module.exports = /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(locals) { var _config$bangumi; - var config, root, wantWatch, watching, watched, _JSON$parse, __, contents; + var config, root, wantWatch, watching, watched, _JSON$parse, wantWatchExtra, watchingExtra, watchedExtra, _JSON$parse2, __, contents; return _regenerator["default"].wrap(function _callee$(_context) { while (1) { @@ -57,22 +57,32 @@ module.exports = /*#__PURE__*/function () { wantWatch = _JSON$parse.wantWatch; watching = _JSON$parse.watching; watched = _JSON$parse.watched; - // extra bangumis console.log(path.join(this.source_dir, '/_data/extra_bangumis.json')); - if(fs.existsSync(path.join(this.source_dir, '/_data/extra_bangumis.json'))) { + + if (fs.existsSync(path.join(this.source_dir, '/_data/extra_bangumis.json'))) { log.info('Found extra bangumi data'); - _JSON$parse = JSON.parse(fs.readFileSync(path.join(this.source_dir, '/_data/extra_bangumis.json'))); - if(_JSON$parse.wantWatch) { - wantWatch = wantWatch.concat(_JSON$parse.wantWatch); + wantWatchExtra = []; + watchingExtra = []; + watchedExtra = []; + _JSON$parse2 = JSON.parse(fs.readFileSync(path.join(this.source_dir, '/_data/extra_bangumis.json'))); + wantWatchExtra = _JSON$parse2.wantWatchExtra; + watchingExtra = _JSON$parse2.watchingExtra; + watchedExtra = _JSON$parse2.watchedExtra; + + if (wantWatchExtra) { + wantWatch = wantWatch.concat(wantWatchExtra); } - if(_JSON$parse.watching) { - watching = watching.concat(_JSON$parse.watching); + + if (watchingExtra) { + watching = watching.concat(watchingExtra); } - if(_JSON$parse.watched) { - watched = watched.concat(_JSON$parse.watched); + + if (watchedExtra) { + watched = watched.concat(watchedExtra); } } + log.info(wantWatch.length + watching.length + watched.length + ' bangumis have been loaded'); } diff --git a/src/lib/bangumi-generator.js b/src/lib/bangumi-generator.js index 62e04b7..de800db 100644 --- a/src/lib/bangumi-generator.js +++ b/src/lib/bangumi-generator.js @@ -19,12 +19,30 @@ module.exports = async function (locals) { if (root.endsWith('/')) { root = root.slice(0, root.length - 1) } - let wantWatch = []; let watching = []; let watched = [] + let wantWatch = []; let watching = []; let watched = []; console.log(path.join(this.source_dir, '/_data/bangumis.json')) if (!fs.existsSync(path.join(this.source_dir, '/_data/bangumis.json'))) { log.info('Can\'t find bilibili bangumi data, please use \'hexo bangumi -u\' command to get data') } else { ({ wantWatch, watching, watched } = JSON.parse(fs.readFileSync(path.join(this.source_dir, '/_data/bangumis.json')))) + + // extra bangumis + console.log(path.join(this.source_dir, '/_data/extra_bangumis.json')) + if(fs.existsSync(path.join(this.source_dir, '/_data/extra_bangumis.json'))) { + log.info('Found extra bangumi data'); + let wantWatchExtra = []; let watchingExtra = []; let watchedExtra = []; + ({ wantWatchExtra, watchingExtra, watchedExtra } = JSON.parse(fs.readFileSync(path.join(this.source_dir, '/_data/extra_bangumis.json')))) + if(wantWatchExtra) { + wantWatch = wantWatch.concat(wantWatchExtra) + } + if(watchingExtra) { + watching = watching.concat(watchingExtra) + } + if(watchedExtra) { + watched = watched.concat(watchedExtra) + } + } + log.info(wantWatch.length + watching.length + watched.length + ' bangumis have been loaded') }