Skip to content

Commit

Permalink
添加从Bangumi获取数据(#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely committed Jan 19, 2022
1 parent 9531c84 commit 9e5884d
Show file tree
Hide file tree
Showing 23 changed files with 11,031 additions and 330 deletions.
223 changes: 223 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"ignorePatterns": [
"./lib/**/*",
"./index.js"
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"prefer-const": [
"error",
{
"destructuring": "any",
"ignoreReadBeforeAssign": false
}
],
"no-var": "error",
"no-new-object": "error",
"object-shorthand": "error",
"quote-props": [
"error",
"as-needed"
],
"prefer-object-spread": "error",
"no-array-constructor": "error",
"array-callback-return": "error",
"prefer-destructuring": [
"error",
{
"array": true,
"object": true
}
],
"prefer-template": "error",
"template-curly-spacing": [
"error",
"never"
],
"no-eval": "error",
"func-style": [
"error",
"expression"
],
"wrap-iife": [
"error",
"outside"
],
"no-loop-func": "error",
"prefer-rest-params": "error",
"default-param-last": "error",
"no-new-func": "error",
"space-before-function-paren": [
"error",
{
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}
],
"space-before-blocks": "error",
"no-param-reassign": "error",
"prefer-spread": "error",
"prefer-arrow-callback": "error",
"arrow-spacing": "error",
"arrow-parens": "error",
"arrow-body-style": "error",
"no-confusing-arrow": [
"error",
{
"allowParens": true
}
],
"implicit-arrow-linebreak": [
"error",
"beside"
],
"no-useless-constructor": "error",
"class-methods-use-this": 0,
"object-curly-newline": [
"error",
{
"ObjectPattern": {
"multiline": true
}
}
],
"no-iterator": "error",
"generator-star-spacing": [
"error",
"after"
],
"dot-notation": "error",
"one-var": [
"error",
"never"
],
"no-multi-assign": "error",
"no-plusplus": "error",
"operator-linebreak": [
"error",
"after"
],
"eqeqeq": "error",
"no-nested-ternary": "error",
"no-unneeded-ternary": "error",
"no-mixed-operators": "error",
"nonblock-statement-body-position": [
"error",
"beside"
],
"brace-style": [
"error",
"1tbs",
{
"allowSingleLine": true
}
],
"no-else-return": "error",
"spaced-comment": [
"error",
"always"
],
"keyword-spacing": "error",
"space-infix-ops": "error",
"eol-last": [
"error",
"always"
],
"newline-per-chained-call": "error",
"no-whitespace-before-property": "error",
"padded-blocks": [
"error",
"never"
],
"no-multiple-empty-lines": [
"error",
{
"max": 1
}
],
"space-in-parens": [
"error",
"never"
],
"array-bracket-spacing": [
"error",
"never"
],
"object-curly-spacing": [
"error",
"always"
],
"max-len": [
"error",
{
"code": 200
}
],
"block-spacing": "error",
"comma-spacing": [
"error",
{
"before": false,
"after": true
}
],
"computed-property-spacing": [
"error",
"never"
],
"func-call-spacing": [
"error",
"never"
],
"key-spacing": "error",
"no-trailing-spaces": "error",
"comma-style": "error",
"comma-dangle": [
"error",
"never"
],
"no-new-wrappers": "error",
"radix": "error",
"camelcase": [
"error",
{
"allow": [
"GM_info"
]
}
],
"new-cap": [
"error",
{
"capIsNewExceptions": [
]
}
],
"no-underscore-dangle": "error"
}
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/
.history/
get-bgm-data.js
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## 介绍

**为 Hexo 添加哔哩哔哩追番/追剧页面,参考自[hexo-douban](https://github.com/mythsman/hexo-douban)**.
**为 Hexo 添加[哔哩哔哩](https://www.bilibili.com/)/[Bangumi](https://bangumi.tv/)追番/追剧页面,参考自[hexo-douban](https://github.com/mythsman/hexo-douban)**.

[Demo](https://demo.hclonely.com/bangumis/)

Expand All @@ -23,6 +23,7 @@ $ npm install hexo-bilibili-bangumi --save
``` yaml
bangumi: # 追番设置
enable: true
source: bili
path:
vmid:
title: '追番列表'
Expand Down Expand Up @@ -54,8 +55,9 @@ cinema: # 追剧设置
```
- **enable**: 是否启用
- **source**: 数据源,仅支持番剧。`bili`: [哔哩哔哩源](https://www.bilibili.com/), `bgm`: [Bangumi源](https://bangumi.tv/)
- **path**: 页面路径,默认`bangumis/index.html`, `cinemas/index.html`
- **vmid**: 哔哩哔哩的 `vmid(uid)`,[如何获取?](#获取uid)
- **vmid**: 哔哩哔哩的 `vmid(uid)`[如何获取?](#获取uid)或Bangumi的用户id
- **title**: 该页面的标题
- **quote**: 写在页面开头的一段话,支持 html 语法,可留空。
- **show**: 初始显示页面:`0: 想看`, `1: 在看`, `2: 看过`,默认为`1`
Expand Down
26 changes: 19 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ var log = require('hexo-log')({
var _require = require('./lib/get-bili-data'),
getBiliData = _require.getBiliData;

if (typeof URL !== 'function') var _require2 = require('url'),
URL = _require2.URL;
var _require2 = require('./lib/get-bgm-data'),
getBgmData = _require2.getBgmData; // eslint-disable-next-line no-var


if (typeof URL !== 'function') var _require3 = require('url'),
URL = _require3.URL;
var options = {
options: [{
name: '-u, --update',
desc: 'Update bilibili data'
desc: 'Update data'
}, {
name: '-d, --delete',
desc: 'Delete bilibili data'
desc: 'Delete data'
}]
};
hexo.extend.generator.register('bangumis', function (locals) {
Expand All @@ -42,14 +46,14 @@ hexo.extend.generator.register('cinemas', function (locals) {

return require('./lib/bangumi-generator').call(this, locals, 'cinema');
});
hexo.extend.console.register('bangumi', 'Generate pages of bilibili bangumis for Hexo', options, function (args) {
hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', options, function (args) {
if (args.d) {
if (fs.existsSync(path.join(this.source_dir, '/_data/bangumis.json'))) {
fs.unlinkSync(path.join(this.source_dir, '/_data/bangumis.json'));
log.info('Bangumis data has been deleted');
}
} else if (args.u) {
var _this$config3, _this$config$bangumi$;
var _this$config3;

if (!(this !== null && this !== void 0 && (_this$config3 = this.config) !== null && _this$config3 !== void 0 && _this$config3.bangumi)) {
log.info('Please add config to _config.yml');
Expand All @@ -65,7 +69,15 @@ hexo.extend.console.register('bangumi', 'Generate pages of bilibili bangumis for
return;
}

getBiliData(this.config.bangumi.vmid, 'bangumi', (_this$config$bangumi$ = this.config.bangumi.progress) !== null && _this$config$bangumi$ !== void 0 ? _this$config$bangumi$ : true, this.source_dir, this.config.bangumi.webp);
if (this.config.bangumi.source === 'bgm') {
var _this$config$bangumi$;

getBgmData(this.config.bangumi.vmid, (_this$config$bangumi$ = this.config.bangumi.progress) !== null && _this$config$bangumi$ !== void 0 ? _this$config$bangumi$ : true, this.source_dir);
} else {
var _this$config$bangumi$2;

getBiliData(this.config.bangumi.vmid, 'bangumi', (_this$config$bangumi$2 = this.config.bangumi.progress) !== null && _this$config$bangumi$2 !== void 0 ? _this$config$bangumi$2 : true, this.source_dir, this.config.bangumi.webp);
}
} else {
log.info('Unknown command, please use "hexo bangumi -h" to see the available commands');
}
Expand Down
25 changes: 14 additions & 11 deletions lib/bangumi-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var ejs = require('ejs');

var path = require('path');

var i18n = require('./util').i18n;
var _require = require('./util'),
i18n = _require.i18n;

var fs = require('hexo-fs');

Expand All @@ -27,7 +28,7 @@ var log = require('hexo-log')({

module.exports = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(locals) {
var _config$type, _config$type$lazyload, _config$type2;
var _config$type, _config$type$lazyload, _config$type$source, _config$type2;

var type,
config,
Expand Down Expand Up @@ -70,22 +71,22 @@ module.exports = /*#__PURE__*/function () {
watching = [];
watched = []; // console.log(path.join(this.source_dir, '/_data/bangumis.json'))

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');
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"));
} else {
_JSON$parse = JSON.parse(fs.readFileSync(path.join(this.source_dir, '/_data/' + type + 's.json')));
_JSON$parse = JSON.parse(fs.readFileSync(path.join(this.source_dir, "/_data/".concat(type, "s.json"))));
wantWatch = _JSON$parse.wantWatch;
watching = _JSON$parse.watching;
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_' + type + 's.json'))) {
log.info('Found extra ' + type + 's data');
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_' + type + 's.json')));
_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;
Expand All @@ -103,8 +104,9 @@ module.exports = /*#__PURE__*/function () {
}
}

log.info(wantWatch.length + watching.length + watched.length + ' ' + type + 's have been loaded');
}
log.info("".concat(wantWatch.length + watching.length + watched.length, " ").concat(type, "s have been loaded"));
} // eslint-disable-next-line no-underscore-dangle


__ = i18n.__(config.language);
_context.next = 13;
Expand All @@ -115,6 +117,7 @@ module.exports = /*#__PURE__*/function () {
metaColor: config[type].metaColor ? "style=\"color:".concat(config[type].metaColor, "\"") : '',
color: config[type].color ? "style=\"color:".concat(config[type].color, "\"") : '',
lazyload: (_config$type$lazyload = config[type].lazyload) !== null && _config$type$lazyload !== void 0 ? _config$type$lazyload : true,
source: (_config$type$source = config[type].source) !== null && _config$type$source !== void 0 ? _config$type$source : 'bili',
wantWatch: wantWatch,
watched: watched,
watching: watching,
Expand All @@ -129,7 +132,7 @@ module.exports = /*#__PURE__*/function () {
contents = _context.sent;
customPath = config[type].path;
return _context.abrupt("return", {
path: customPath || type + 's/index.html',
path: customPath || "".concat(type, "s/index.html"),
data: _objectSpread({
title: config[type].title,
content: contents
Expand Down
Loading

0 comments on commit 9e5884d

Please sign in to comment.