Skip to content

Commit

Permalink
添加番剧封面格式配置(#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely committed Jul 4, 2020
1 parent 186f423 commit 58e0799
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 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:
loading:
metaColor:
color:
webp:
```
- **enable**: 是否启用
Expand All @@ -42,6 +43,7 @@ bangumi:
- **loading**: 图片加载完成前的loading图片
- **metaColor**: meta部分(简介上方)字体颜色
- **color**: 简介字体颜色
- **webp**: 番剧封面使用`webp`格式(此格式在`safari`浏览器下不显示,但是图片大小可以缩小100倍左右), 默认`true`

## 使用

Expand Down
3 changes: 1 addition & 2 deletions lib/templates/bangumi.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@
<% include index.js %>
tabs[<%- show %>].click();
<% include pagination.js %>
<% include webpSupport.js %>
</script>
</script>
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.3.2",
"version": "1.3.3",
"description": "hexo bilibili番剧页",
"main": "index.js",
"scripts": {
Expand Down
20 changes: 10 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ hexo.extend.console.register('bangumi', 'Generate pages of bilibili bangumis for
log.info("Please add vmid to _config.yml");
return;
}
saveBangumiData(this.config.bangumi.vmid);
saveBangumiData(this.config.bangumi.vmid, this.config.bangumi.webp);
} else {
log.info("Unknown command, please use \"hexo bangumi -h\" to see the available commands")
}
Expand All @@ -58,7 +58,7 @@ async function getBangumiPage(vmid, status) {
return { success: false, data: response };
}
}
async function getBangumi(vmid, status, pn) {
async function getBangumi(vmid, status, webp, pn) {
let response = await axios.get(`https://api.bilibili.com/x/space/bangumi/follow/list?type=1&follow_status=${status}&vmid=${vmid}&ps=50&pn=${pn}`)
let $data = [];
if (response?.data?.code === 0) {
Expand All @@ -69,7 +69,7 @@ async function getBangumi(vmid, status, pn) {
if (cover){
let href = new URL(cover)
href.protocol = 'https'
href.pathname += '@220w_280h.webp'
if(webp) href.pathname += '@220w_280h.webp'
cover = href.href
}
$data.push({
Expand All @@ -96,12 +96,12 @@ function count(e) {
function total(e) {
return e ? (e === -1 ? `未完结` : `全${e}话`) : '-';
}
async function biliBangumi(vmid, status) {
let page = await getBangumiPage(vmid, status);
async function biliBangumi(vmid, status, webp) {
let page = await getBangumiPage(vmid, status, webp);
if(page?.success){
let list = [];
for (let i = 1; i < page.data; i++) {
let data = await getBangumi(vmid, status, i);
let data = await getBangumi(vmid, status, webp, i);
list.push(...data);
}
return list;
Expand All @@ -110,12 +110,12 @@ async function biliBangumi(vmid, status) {
return [];
}
}
async function saveBangumiData(vmid) {
async function saveBangumiData(vmid, webp = true) {
log.info("Getting bilibili bangumis, please wait...");
let startTime = new Date().getTime();
let wantWatch = await biliBangumi(vmid, 1);
let watching = await biliBangumi(vmid, 2);
let watched = await biliBangumi(vmid, 3);
let wantWatch = await biliBangumi(vmid, 1, webp);
let watching = await biliBangumi(vmid, 2, webp);
let watched = await biliBangumi(vmid, 3, webp);
let endTime = new Date().getTime();
log.info(wantWatch.length + watching.length + watched.length + ' bangumis have been loaded in ' + (endTime - startTime) + " ms");
let bangumis = { wantWatch, watching, watched };
Expand Down
4 changes: 0 additions & 4 deletions src/lib/templates/webpSupport.js

This file was deleted.

0 comments on commit 58e0799

Please sign in to comment.