Skip to content

Commit

Permalink
添加按评分排序功能(#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely committed Sep 6, 2023
1 parent d08cd62 commit 50f4016
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bangumi: # 追番设置
webp:
progress:
extraOrder:
order: latest
proxy:
host: '代理host'
port: '代理端口'
Expand All @@ -62,6 +63,7 @@ cinema: # 追剧设置
webp:
progress:
extraOrder:
order:
extra_options:
key: value
```
Expand All @@ -88,6 +90,7 @@ cinema: # 追剧设置
- **extraOrder**: 手动添加的番剧/追剧数据是否优先显示,`1`为优先,其它为不优先
- **showMyComment**: 使用`bgm`源时显示自己的评价及评论,默认`false`
- **pagination**: 分页优化,只将第一页的数据渲染到`html`文件中,其余数据将通过异步请求加载,避免番剧过多时html文件过大导致页面加载缓慢,建议番剧较多时使用,默认`false`
- **order**: 排序,支持`latest`(默认,按添加时间排序), `score`(评分升序), `-score`(评分降序)
- **extra_options**: 此配置会扩展到Hexo`page`变量中

## 使用
Expand Down
12 changes: 9 additions & 3 deletions lib/bangumi-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ module.exports = /*#__PURE__*/function () {
pagination: (_config$type$paginati = config[type].pagination) !== null && _config$type$paginati !== void 0 ? _config$type$paginati : false,
theme: fs.existsSync(path.join(__dirname, "templates/theme/".concat(config.theme, ".min.css"))) ? config.theme : null,
ejsTemplate: fs.readFileSync(path.join(__dirname, "templates/".concat(config[type].source === 'bili' ? 'bili' : 'bgm', "-template.ejs"))).toString().replace('class="bangumi-item"', 'class="bangumi-item bangumi-hide"'),
wantWatch: wantWatch,
watched: watched,
watching: watching,
wantWatch: ['score', '-score'].includes(config[type].order) ? wantWatch.sort(function (a, b) {
return config[type].order === 'score' ? a.score - b.score : b.score - a.score;
}) : wantWatch,
watched: ['score', '-score'].includes(config[type].order) ? watched.sort(function (a, b) {
return config[type].order === 'score' ? a.score - b.score : b.score - a.score;
}) : watched,
watching: ['score', '-score'].includes(config[type].order) ? watching.sort(function (a, b) {
return config[type].order === 'score' ? a.score - b.score : b.score - a.score;
}) : watching,
type: type,
__: __,
root: root
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.8.8",
"version": "1.8.9",
"description": "hexo bilibili番剧页",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/bangumi-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ module.exports = async function (locals, type = 'bangumi') {
theme: fs.existsSync(path.join(__dirname, `templates/theme/${config.theme}.min.css`)) ? config.theme : null,
ejsTemplate: fs.readFileSync(path.join(__dirname, `templates/${config[type].source === 'bili' ? 'bili' : 'bgm'}-template.ejs`)).toString()
.replace('class="bangumi-item"', 'class="bangumi-item bangumi-hide"'),
wantWatch,
watched,
watching,
wantWatch: ['score', '-score'].includes(config[type].order) ? wantWatch.sort((a, b) => (config[type].order === 'score' ? (a.score - b.score) : (b.score - a.score))) : wantWatch,
watched: ['score', '-score'].includes(config[type].order) ? watched.sort((a, b) => (config[type].order === 'score' ? (a.score - b.score) : (b.score - a.score))) : watched,
watching: ['score', '-score'].includes(config[type].order) ? watching.sort((a, b) => (config[type].order === 'score' ? (a.score - b.score) : (b.score - a.score))) : watching,
type,
__,
root
Expand Down

0 comments on commit 50f4016

Please sign in to comment.