From ed41b003cf50060973ba6ce64f76dbaf00843379 Mon Sep 17 00:00:00 2001 From: JiJi Date: Wed, 10 Mar 2021 20:11:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=95=AA=E5=89=A7=E6=95=B0=E6=8D=AE=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持从sources/_data/extra_bangumis.json手动载入番剧数据,详情见README.md --- README.md | 37 +++++++++++++++++++++++++++++++++++++ lib/bangumi-generator.js | 16 ++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/README.md b/README.md index 1b42f56..b402022 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,43 @@ bangumi: ![示例图片](https://github.com/HCLonely/hexo-bilibili-bangumi/raw/master/example.png) +## 手动添加番剧数据 +因为某些番剧在哔哩哔哩上没有,但是又想在hexo中展示,怎么办呢?现在支持手动添加番剧数据了! + +在 `sources/_data/` 目录下新建文件,命名为 `extra_bangumis.json` ,并添加以如下内容: +```json +{ + "watched": [ + { + "title": "缘之空", + "type": "番剧", + "area": "日本", + "cover": "https://cdn.jsdelivr.net/gh/mmdjiji/bangumis@main/Yosuga-no-Sora/cover.jpg", + "totalCount": "全12话", + "id": 0, + "follow": "不可用", + "view": "不可用", + "danmaku": "不可用", + "coin": "不可用", + "score": "不可用", + "des": "远离都市的田园小镇,奥木染。春日野悠带着妹妹穹,来到了这座城镇。坐落在这里的是,儿时暑假经常造访的充满回忆的已故祖父的家。双亲因意外事故而丧生,变得无依无靠..." + } + ] +} +``` + +`title` 是番剧的标题,`cover` 是封面图链接, `des` 是简介,上述字段均根据需要修改。 + +另外除了 `watched` 数组,还可以在后面添加新的数组,可用数组名如下: + +|可用数组名|含义| +|-|-| +|wantWatch|想看| +|watching|在看| +|watched|看过| + +需要注意,在两个数组之间需要用 `,` 分隔。 + ## Lisense [Apache Licence 2.0](https://github.com/HCLonely/hexo-bilibili-bangumi/blob/master/LICENSE) diff --git a/lib/bangumi-generator.js b/lib/bangumi-generator.js index 208cea3..3ce4def 100644 --- a/lib/bangumi-generator.js +++ b/lib/bangumi-generator.js @@ -57,6 +57,22 @@ 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'))) { + 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); + } + if(_JSON$parse.watching) { + watching = watching.concat(_JSON$parse.watching); + } + if(_JSON$parse.watched) { + watched = watched.concat(_JSON$parse.watched); + } + } log.info(wantWatch.length + watching.length + watched.length + ' bangumis have been loaded'); } From faf0e5edff274c2a9569fe083285dbe922be8bbb Mon Sep 17 00:00:00 2001 From: JiJi Date: Wed, 10 Mar 2021 22:30:19 +0800 Subject: [PATCH 2/2] =?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') }