Skip to content

Commit

Permalink
Merge pull request #15 from mmdjiji/master
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely authored Mar 11, 2021
2 parents b5f2235 + faf0e5e commit 9349e77
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
28 changes: 27 additions & 1 deletion lib/bangumi-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -57,6 +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'))) {
log.info('Found extra bangumi data');
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 (watchingExtra) {
watching = watching.concat(watchingExtra);
}

if (watchedExtra) {
watched = watched.concat(watchedExtra);
}
}

log.info(wantWatch.length + watching.length + watched.length + ' bangumis have been loaded');
}

Expand Down
20 changes: 19 additions & 1 deletion src/lib/bangumi-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

Expand Down

0 comments on commit 9349e77

Please sign in to comment.