Skip to content

Commit

Permalink
使用bgm源是可以显示自己的评分及评价[需配置showMyComment: true](#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely committed Jul 11, 2022
1 parent b27e9eb commit 9c81082
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 123 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bangumi: # 追番设置
show: 1
lazyload: true
loading:
showMyComment: false
metaColor:
color:
webp:
Expand Down Expand Up @@ -76,6 +77,7 @@ cinema: # 追剧设置
- **webp**: 番剧封面使用`webp`格式(此格式在`safari`浏览器下不显示,但是图片大小可以缩小 100 倍左右,仅支持哔哩哔哩源), 默认`true`
- **progress**: 获取番剧数据时是否显示进度条,默认`true`
- **extraOrder**: 手动添加的番剧/追剧数据是否优先显示,`1`为优先,其它为不优先
- **showMyComment**: 使用`bgm`源时显示自己的评价及评论,默认`false`
- **extra_options**: 此配置会扩展到Hexo`page`变量中

## 使用
Expand Down
3 changes: 2 additions & 1 deletion lib/bangumi-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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$type$source, _config$type2;
var _config$type, _config$type$lazyload, _config$type$source, _config$type$showMyCo, _config$type2;

var type,
config,
Expand Down Expand Up @@ -125,6 +125,7 @@ module.exports = /*#__PURE__*/function () {
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',
showMyComment: (_config$type$showMyCo = config[type].showMyComment) !== null && _config$type$showMyCo !== void 0 ? _config$type$showMyCo : false,
wantWatch: wantWatch,
watched: watched,
watching: watching,
Expand Down
16 changes: 13 additions & 3 deletions lib/get-bgm-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ var getItemsId = /*#__PURE__*/function () {
_context2.t2 = _toConsumableArray2["default"];
_context2.next = 15;
return getBangumiData($('#browserItemList>li').map(function (index, el) {
var _$$find$attr, _$$find$attr$match;

return {
id: $(el).attr('id').replace('item_', ''),
cover: $(el).find('img').attr('src'),
name: $(el).find('h3>a').text()
name: $(el).find('h3>a').text(),
myStars: (_$$find$attr = $(el).find('.starlight').attr('class')) === null || _$$find$attr === void 0 ? void 0 : (_$$find$attr$match = _$$find$attr.match(/stars([\d]+)/)) === null || _$$find$attr$match === void 0 ? void 0 : _$$find$attr$match[1],
myComment: $(el).find('#comment_box').text().trim()
};
}).get(), sourceDir, proxy);

Expand Down Expand Up @@ -120,10 +124,14 @@ var getItemsId = /*#__PURE__*/function () {
_context.t2 = _toConsumableArray2["default"];
_context.next = 10;
return getBangumiData($('#browserItemList>li').map(function (index, el) {
var _$$find$attr2, _$$find$attr2$match;

return {
id: $(el).attr('id').replace('item_', ''),
cover: $(el).find('img').attr('src'),
name: $(el).find('h3>a').text()
name: $(el).find('h3>a').text(),
myStars: (_$$find$attr2 = $(el).find('.starlight').attr('class')) === null || _$$find$attr2 === void 0 ? void 0 : (_$$find$attr2$match = _$$find$attr2.match(/stars([\d]+)/)) === null || _$$find$attr2$match === void 0 ? void 0 : _$$find$attr2$match[1],
myComment: $(el).find('#comment_box').text().trim()
};
}).get(), sourceDir, proxy);

Expand Down Expand Up @@ -362,7 +370,9 @@ var getBangumiData = /*#__PURE__*/function () {
wish: wish || '-',
doing: doing || '-',
collect: collect || '-',
totalCount: totalCount ? "\u5168".concat(totalCount, "\u8BDD") : '-'
totalCount: totalCount ? "\u5168".concat(totalCount, "\u8BDD") : '-',
myStars: config.itemData.myStars,
myComment: config.itemData.myComment
};
}));

Expand Down
Binary file added lib/img/rate_star_2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion lib/templates/bgm-template.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
</span>
</span>
</div>
<div class="bangumi-comments" <%- color %>><p>简介:<%= item.des || "暂无简介" %></p> </div>
<div class="bangumi-comments" <%- color %>>
<p>简介:<%= item.des || "暂无简介" %></p>
<% if (showMyComment && item.myComment) { %>
<div class="bangumi-my-comments">我的评分:
<% if (item.myStars) { %>
<span class="bangumi-starstop"><span class="bangumi-starlight stars<%= item.myStars %>"></span></span>
<% } %>
<br>
我的评价:<%= item.myComment %>
</div>
<% } %>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion lib/templates/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.8",
"version": "1.7.9",
"description": "hexo bilibili番剧页",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/lib/bangumi-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module.exports = async function (locals, type = 'bangumi') {
color: config[type].color ? `style="color:${config[type].color}"` : '',
lazyload: config[type].lazyload ?? true,
source: config[type].source ?? 'bili',
showMyComment: config[type].showMyComment ?? false,
wantWatch,
watched,
watching,
Expand Down
16 changes: 15 additions & 1 deletion src/lib/get-bgm-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ const getItemsId = async (vmid, status, showProgress, sourceDir, proxy) => {
cover: $(el).find('img')
.attr('src'),
name: $(el).find('h3>a')
.text(),
myStars: $(el).find('.starlight')
.attr('class')
?.match(/stars([\d]+)/)?.[1],
myComment: $(el).find('#comment_box')
.text()
.trim()
}))
.get(), sourceDir, proxy));

Expand All @@ -58,7 +64,13 @@ const getItemsId = async (vmid, status, showProgress, sourceDir, proxy) => {
cover: $(el).find('img')
.attr('src'),
name: $(el).find('h3>a')
.text(),
myStars: $(el).find('.starlight')
.attr('class')
?.match(/stars([\d]+)/)?.[1],
myComment: $(el).find('#comment_box')
.text()
.trim()
}))
.get(), sourceDir, proxy));
}
Expand Down Expand Up @@ -164,7 +176,9 @@ const getBangumiData = async (items, sourceDir, proxy) => (await Promise.allSett
wish: wish || '-',
doing: doing || '-',
collect: collect || '-',
totalCount: totalCount ? `全${totalCount}话` : '-'
totalCount: totalCount ? `全${totalCount}话` : '-',
myStars: config.itemData.myStars,
myComment: config.itemData.myComment
};
});

Expand Down
Loading

0 comments on commit 9c81082

Please sign in to comment.