Skip to content

Commit

Permalink
添加手动添加的数据是否优先显示的配置(close #129)
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely committed May 24, 2022
1 parent 07afe18 commit 3d3285c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ bangumi: # 追番设置
color:
webp:
progress:
extraOrder:
proxy:
host: '代理host'
port: '代理端口'
Expand All @@ -53,15 +54,18 @@ cinema: # 追剧设置
color:
webp:
progress:
extraOrder:
extra_options:
key: value
```
- **enable**: 是否启用
> 带*为必填选项!
- **enable\***: 是否启用
- **source**: 数据源,仅支持追番,追剧仅支持哔哩哔哩源。`bili`: [哔哩哔哩源](https://www.bilibili.com/), `bgm`: [Bangumi源](https://bangumi.tv/)
- **proxy**: 代理设置,仅在使用支持`bgm`源追番时生效。默认`false`
- **path**: 页面路径,默认`bangumis/index.html`, `cinemas/index.html`
- **vmid**: 哔哩哔哩的 `vmid(uid)`[如何获取?](#获取-bilibili-uid)或Bangumi的用户`id`[如何获取?](#获取-bangumi-id)
- **vmid\***: 哔哩哔哩的 `vmid(uid)`[如何获取?](#获取-bilibili-uid)或Bangumi的用户`id`[如何获取?](#获取-bangumi-id)
- **title**: 该页面的标题
- **quote**: 写在页面开头的一段话,支持 html 语法,可留空。
- **show**: 初始显示页面:`0: 想看`, `1: 在看`, `2: 看过`,默认为`1`
Expand All @@ -71,6 +75,7 @@ cinema: # 追剧设置
- **color**: 简介字体颜色
- **webp**: 番剧封面使用`webp`格式(此格式在`safari`浏览器下不显示,但是图片大小可以缩小 100 倍左右,仅支持哔哩哔哩源), 默认`true`
- **progress**: 获取番剧数据时是否显示进度条,默认`true`
- **extraOrder**: 手动添加的番剧/追剧数据是否优先显示,`1`为优先,其它为不优先
- **extra_options**: 此配置会扩展到Hexo`page`变量中

## 使用
Expand Down
33 changes: 20 additions & 13 deletions lib/bangumi-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
Expand Down Expand Up @@ -37,10 +39,10 @@ module.exports = /*#__PURE__*/function () {
watching,
watched,
_JSON$parse,
_JSON$parse2,
wantWatchExtra,
watchingExtra,
watchedExtra,
_JSON$parse2,
__,
contents,
customPath,
Expand Down Expand Up @@ -69,7 +71,7 @@ module.exports = /*#__PURE__*/function () {

wantWatch = [];
watching = [];
watched = []; // console.log(path.join(this.source_dir, '/_data/bangumis.json'))
watched = [];

if (!fs.existsSync(path.join(this.source_dir, "/_data/".concat(type, "s.json")))) {
log.info("Can't find bilibili ".concat(type, " data, please use 'hexo ").concat(type, " -u' command to get data"));
Expand All @@ -80,27 +82,32 @@ module.exports = /*#__PURE__*/function () {
watched = _JSON$parse.watched;

// extra bangumis
// console.log(path.join(this.source_dir, '/_data/extra_' + type + 's.json'))
if (fs.existsSync(path.join(this.source_dir, "/_data/extra_".concat(type, "s.json")))) {
log.info("Found extra ".concat(type, "s data"));
wantWatchExtra = [];
watchingExtra = [];
watchedExtra = [];
_JSON$parse2 = JSON.parse(fs.readFileSync(path.join(this.source_dir, "/_data/extra_".concat(type, "s.json"))));
wantWatchExtra = _JSON$parse2.wantWatchExtra;
watchingExtra = _JSON$parse2.watchingExtra;
watchedExtra = _JSON$parse2.watchedExtra;
_JSON$parse2 = JSON.parse(fs.readFileSync(path.join(this.source_dir, "/_data/extra_".concat(type, "s.json")))), wantWatchExtra = _JSON$parse2.wantWatchExtra, watchingExtra = _JSON$parse2.watchingExtra, watchedExtra = _JSON$parse2.watchedExtra;

if (wantWatchExtra) {
wantWatch = wantWatch.concat(wantWatchExtra);
if (config[type].extraOrder === 1) {
wantWatch = [].concat((0, _toConsumableArray2["default"])(wantWatchExtra), (0, _toConsumableArray2["default"])(wantWatch));
} else {
wantWatch = [].concat((0, _toConsumableArray2["default"])(wantWatch), (0, _toConsumableArray2["default"])(wantWatchExtra));
}
}

if (watchingExtra) {
watching = watching.concat(watchingExtra);
if (config[type].extraOrder === 1) {
watching = [].concat((0, _toConsumableArray2["default"])(watchingExtra), (0, _toConsumableArray2["default"])(watching));
} else {
watching = [].concat((0, _toConsumableArray2["default"])(watching), (0, _toConsumableArray2["default"])(watchingExtra));
}
}

if (watchedExtra) {
watched = watched.concat(watchedExtra);
if (config[type].extraOrder === 1) {
watched = [].concat((0, _toConsumableArray2["default"])(watchedExtra), (0, _toConsumableArray2["default"])(watched));
} else {
watched = [].concat((0, _toConsumableArray2["default"])(watched), (0, _toConsumableArray2["default"])(watchedExtra));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-bilibili-bangumi",
"version": "1.7.7",
"version": "1.7.8",
"description": "hexo bilibili番剧页",
"main": "index.js",
"scripts": {
Expand Down
27 changes: 19 additions & 8 deletions src/lib/bangumi-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,38 @@ module.exports = async function (locals, type = 'bangumi') {
if (root.endsWith('/')) {
root = root.slice(0, root.length - 1);
}
let wantWatch = []; let watching = []; let watched = [];
// console.log(path.join(this.source_dir, '/_data/bangumis.json'))
let wantWatch = [];
let watching = [];
let watched = [];
if (!fs.existsSync(path.join(this.source_dir, `/_data/${type}s.json`))) {
log.info(`Can't find bilibili ${type} data, please use 'hexo ${type} -u' command to get data`);
} else {
({ wantWatch, watching, watched } = JSON.parse(fs.readFileSync(path.join(this.source_dir, `/_data/${type}s.json`))));

// extra bangumis
// console.log(path.join(this.source_dir, '/_data/extra_' + type + 's.json'))
if (fs.existsSync(path.join(this.source_dir, `/_data/extra_${type}s.json`))) {
log.info(`Found extra ${type}s data`);
let wantWatchExtra = []; let watchingExtra = []; let watchedExtra = [];
({ wantWatchExtra, watchingExtra, watchedExtra } = JSON.parse(fs.readFileSync(path.join(this.source_dir, `/_data/extra_${type}s.json`))));
const { wantWatchExtra, watchingExtra, watchedExtra } = JSON.parse(fs.readFileSync(path.join(this.source_dir, `/_data/extra_${type}s.json`)));
if (wantWatchExtra) {
wantWatch = wantWatch.concat(wantWatchExtra);
if (config[type].extraOrder === 1) {
wantWatch = [...wantWatchExtra, ...wantWatch];
} else {
wantWatch = [...wantWatch, ...wantWatchExtra];
}
}
if (watchingExtra) {
watching = watching.concat(watchingExtra);
if (config[type].extraOrder === 1) {
watching = [...watchingExtra, ...watching];
} else {
watching = [...watching, ...watchingExtra];
}
}
if (watchedExtra) {
watched = watched.concat(watchedExtra);
if (config[type].extraOrder === 1) {
watched = [...watchedExtra, ...watched];
} else {
watched = [...watched, ...watchedExtra];
}
}
}

Expand Down

0 comments on commit 3d3285c

Please sign in to comment.