Skip to content

Commit

Permalink
fix #264
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely committed Feb 28, 2023
1 parent 837e8a3 commit e10ecf8
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 292 deletions.
32 changes: 9 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
'use strict';

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

var path = require('path');

var log = require('hexo-log')({
var hexoLog = require('hexo-log');
var log = typeof hexoLog["default"] === 'function' ? hexoLog["default"]({
debug: false,
silent: false
}) : hexoLog({
debug: false,
silent: false
});

var _require = require('./lib/get-bili-data'),
getBiliData = _require.getBiliData;

getBiliData = _require.getBiliData;
var _require2 = require('./lib/get-bgm-data'),
getBgmData = _require2.getBgmData; // eslint-disable-next-line no-var

getBgmData = _require2.getBgmData;

// eslint-disable-next-line no-var
if (typeof URL !== 'function') var _require3 = require('url'),
URL = _require3.URL;
URL = _require3.URL;
var options = {
options: [{
name: '-u, --update',
Expand All @@ -30,20 +30,16 @@ var options = {
};
hexo.extend.generator.register('bangumis', function (locals) {
var _this$config, _this$config$bangumi;

if (!(this !== null && this !== void 0 && (_this$config = this.config) !== null && _this$config !== void 0 && (_this$config$bangumi = _this$config.bangumi) !== null && _this$config$bangumi !== void 0 && _this$config$bangumi.enable)) {
return;
}

return require('./lib/bangumi-generator').call(this, locals, 'bangumi');
});
hexo.extend.generator.register('cinemas', function (locals) {
var _this$config2, _this$config2$cinema;

if (!(this !== null && this !== void 0 && (_this$config2 = this.config) !== null && _this$config2 !== void 0 && (_this$config2$cinema = _this$config2.cinema) !== null && _this$config2$cinema !== void 0 && _this$config2$cinema.enable)) {
return;
}

return require('./lib/bangumi-generator').call(this, locals, 'cinema');
});
hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', options, function (args) {
Expand All @@ -54,24 +50,19 @@ hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', o
}
} else if (args.u) {
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');
return;
}

if (!this.config.bangumi.enable) {
return;
}

if (!this.config.bangumi.vmid) {
log.info('Please add vmid to _config.yml');
return;
}

if (['bgm', 'bangumi'].includes(this.config.bangumi.source)) {
var _this$config$bangumi$;

getBgmData({
vmid: this.config.bangumi.vmid,
showProgress: (_this$config$bangumi$ = this.config.bangumi.progress) !== null && _this$config$bangumi$ !== void 0 ? _this$config$bangumi$ : true,
Expand All @@ -84,7 +75,6 @@ hexo.extend.console.register('bangumi', 'Generate pages of bangumis for Hexo', o
});
} else {
var _this$config$bangumi$2;

getBiliData({
vmid: this.config.bangumi.vmid,
type: 'bangumi',
Expand All @@ -107,21 +97,17 @@ hexo.extend.console.register('cinema', 'Generate pages of bilibili cinemas for H
}
} else if (args.u) {
var _this$config4, _this$config$cinema$p;

if (!(this !== null && this !== void 0 && (_this$config4 = this.config) !== null && _this$config4 !== void 0 && _this$config4.cinema)) {
log.info('Please add config to _config.yml');
return;
}

if (!this.config.cinema.enable) {
return;
}

if (!this.config.cinema.vmid) {
log.info('Please add vmid to _config.yml');
return;
}

getBiliData({
vmid: this.config.cinema.vmid,
type: 'cinema',
Expand Down
70 changes: 23 additions & 47 deletions lib/bangumi-generator.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,90 @@
'use strict';

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

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; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

var ejs = require('ejs');

var path = require('path');

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

i18n = _require.i18n;
var fs = require('hexo-fs');

var log = require('hexo-log')({
var hexoLog = require('hexo-log');
var log = typeof hexoLog["default"] === 'function' ? hexoLog["default"]({
debug: false,
silent: false
}) : hexoLog({
debug: false,
silent: false
});

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

var type,
config,
full_url_for,
root,
wantWatch,
watching,
watched,
_JSON$parse,
_JSON$parse2,
wantWatchExtra,
watchingExtra,
watchedExtra,
__,
contents,
customPath,
_args = arguments;

config,
full_url_for,
root,
wantWatch,
watching,
watched,
_JSON$parse,
_JSON$parse2,
wantWatchExtra,
watchingExtra,
watchedExtra,
__,
contents,
customPath,
_args = arguments;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
type = _args.length > 1 && _args[1] !== undefined ? _args[1] : 'bangumi';
config = this.config;

if (config !== null && config !== void 0 && (_config$type = config[type]) !== null && _config$type !== void 0 && _config$type.enable) {
_context.next = 4;
break;
}

return _context.abrupt("return");

case 4:
// eslint-disable-next-line camelcase
full_url_for = this.extend.helper.get('full_url_for').bind(this);
root = config.root;

if (root.endsWith('/')) {
root = root.slice(0, root.length - 1);
}

wantWatch = [];
watching = [];
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"));
} else {
_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
if (fs.existsSync(path.join(this.source_dir, "/_data/extra_".concat(type, "s.json")))) {
log.info("Found extra ".concat(type, "s data"));
_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) {
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) {
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) {
if (config[type].extraOrder === 1) {
watched = [].concat((0, _toConsumableArray2["default"])(watchedExtra), (0, _toConsumableArray2["default"])(watched));
Expand All @@ -113,11 +93,10 @@ module.exports = /*#__PURE__*/function () {
}
}
}

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

}

// eslint-disable-next-line no-underscore-dangle
__ = i18n.__(config.language);
_context.next = 14;
return ejs.renderFile(path.join(__dirname, 'templates/bangumi.ejs'), {
Expand All @@ -142,7 +121,6 @@ module.exports = /*#__PURE__*/function () {
}, {
async: false
});

case 14:
contents = _context.sent;
customPath = config[type].path || "".concat(type, "s/index.html");
Expand All @@ -155,15 +133,13 @@ module.exports = /*#__PURE__*/function () {
}, config === null || config === void 0 ? void 0 : (_config$type2 = config[type]) === null || _config$type2 === void 0 ? void 0 : _config$type2.extra_options),
layout: ['page', 'post']
});

case 17:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));

return function (_x) {
return _ref.apply(this, arguments);
};
Expand Down
Loading

0 comments on commit e10ecf8

Please sign in to comment.