Skip to content

Commit b151fc8

Browse files
committed
图片使用浏览器原生懒加载方式,兼容其他主题懒加载(#134)
1 parent 8c98263 commit b151fc8

16 files changed

+43
-46
lines changed

README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ bangumi: # 追番设置
4242
quote: '生命不息,追番不止!' # 页面引言
4343
show: 1 # 初始显示页面: 0=想看, 1=在看, 2=看过
4444
lazyload: true # 是否启用图片懒加载
45-
loading: # 加载动画
4645
metaColor: # meta 信息字体颜色
4746
color: # 简介字体颜色
4847
webp: true # 是否使用 webp 格式图片
@@ -73,8 +72,8 @@ bangumi: # 追番设置
7372
show: 1
7473
lazyload: true
7574
srcValue: '__image__'
76-
lazyloadAttrName: 'data-src=__image__'
77-
loading:
75+
# lazyloadAttrName: 'data-src=__image__' # 已弃用
76+
# loading: 已弃用
7877
showMyComment: false
7978
pagination: false
8079
metaColor:
@@ -99,8 +98,6 @@ cinema: # 追剧设置
9998
show: 1
10099
lazyload: true
101100
srcValue: '__image__'
102-
lazyloadAttrName: 'data-src=__image__'
103-
loading:
104101
metaColor:
105102
color:
106103
webp:
@@ -121,8 +118,6 @@ game: # 游戏设置,仅支持source: bgmv0
121118
show: 1
122119
lazyload: true
123120
srcValue: '__image__'
124-
lazyloadAttrName: 'data-src=__image__'
125-
loading:
126121
metaColor:
127122
color:
128123
webp:
@@ -157,8 +152,6 @@ game: # 游戏设置,仅支持source: bgmv0
157152
| show | number | 1 | 初始显示的内容类型:0=想看,1=在看,2=看过 |
158153
| lazyload | boolean | true | 是否启用图片懒加载,可避免首次加载时间过长 |
159154
| srcValue | string | '\_\_image\_\_' | 设置封面图的默认src值,`__image__`为封面链接,`__loading__`为loading图片链接 |
160-
| lazyloadAttrName | string | 'data-src=\_\_image\_\_' | 懒加载属性名称和值的格式 |
161-
| loading | string | - | 加载中显示的图片URL |
162155
| metaColor | string | - | meta信息的字体颜色,支持CSS颜色值(如'#FFFFFF') |
163156
| color | string | - | 简介文字的字体颜色 |
164157

lib/bangumi-generator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
1010
/*
1111
* @Author : HCLonely
1212
* @Date : 2024-09-11 15:40:57
13-
* @LastEditTime : 2025-07-10 17:50:02
13+
* @LastEditTime : 2025-08-15 09:58:47
1414
* @LastEditors : HCLonely
1515
* @FilePath : /hexo-bilibili-bangumi/src/lib/bangumi-generator.js
1616
* @Description : Hexo页面生成器模块,负责生成番剧、影视和游戏的展示页面。
@@ -120,11 +120,11 @@ module.exports = /*#__PURE__*/function () {
120120
return pug.renderFile(path.join(__dirname, 'templates/bangumi.pug'), {
121121
quote: config[type].quote,
122122
show: config[type].show || 1,
123-
loading: config[type].loading,
123+
// loading: config[type].loading,
124124
metaColor: config[type].metaColor,
125125
color: config[type].color,
126126
lazyload: (_config$type$lazyload = config[type].lazyload) !== null && _config$type$lazyload !== void 0 ? _config$type$lazyload : true,
127-
lazyloadAttrName: config[type].lazyloadAttrName,
127+
// lazyloadAttrName: config[type].lazyloadAttrName,
128128
srcValue: config[type].srcValue || '__image__',
129129
source: (_config$type$source = config[type].source) !== null && _config$type$source !== void 0 ? _config$type$source : 'bili',
130130
showMyComment: (_config$type$showMyCo = config[type].showMyComment) !== null && _config$type$showMyCo !== void 0 ? _config$type$showMyCo : false,

lib/templates/anilist-template.pug

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.bangumi-item
22
.bangumi-picture
33
img(
4-
src=lazyload ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (srcValue === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : 'https:' + item.cover.replace(/^https:/, ''))
5-
data-src=lazyload ? item.cover : null
4+
src=('https:' + item.cover.replace(/^https:/, ''))
65
referrerpolicy="no-referrer"
6+
loading=lazyload ? "lazy" : "eager"
77
width="110"
88
style="width:110px;margin:20px auto;"
9-
)&attributes(lazyloadAttrName ? {[lazyloadAttrName.split('=')[0]]: lazyloadAttrName.split('=')[1] === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (lazyloadAttrName.split('=')[1] === '__image__' ? 'https:' + item.cover.replace(/^https:/, '') : (lazyloadAttrName.split('=')[1] || ''))} : {})
9+
)
1010

1111
.bangumi-info
1212
.bangumi-title

lib/templates/bangumi-template.pug

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.bangumi-item
22
.bangumi-picture
33
img(
4-
src=lazyload ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (srcValue === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : 'https:' + item.cover.replace(/^https:/, ''))
5-
data-src=lazyload ? item.cover : null
4+
src=('https:' + item.cover.replace(/^https:/, ''))
65
referrerpolicy="no-referrer"
6+
loading=lazyload ? "lazy" : "eager"
77
width="110"
88
style="width:110px;margin:20px auto;"
9-
)&attributes(lazyload ? {} : (lazyloadAttrName ? {[lazyloadAttrName.split('=')[0]]: lazyloadAttrName.split('=')[1] === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (lazyloadAttrName.split('=')[1] === '__image__' ? 'https:' + item.cover.replace(/^https:/, '') : (lazyloadAttrName.split('=')[1] || ''))} : {}))
9+
)
1010
.bangumi-info
1111
.bangumi-title
1212
a(target="_blank" href='https://bangumi.tv/subject/' + item.id)= item.title || __('unknown')

lib/templates/bgm-template.pug

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
.bangumi-item
22
.bangumi-picture
33
img(
4-
src=lazyload ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (srcValue === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : 'https:' + item.cover.replace(/^https:/, ''))
4+
src=('https:' + item.cover.replace(/^https:/, ''))
55
data-src=lazyload ? item.cover : null
66
referrerpolicy="no-referrer"
7+
loading=lazyload ? "lazy" : "eager"
78
width="110"
89
style="width:110px;margin:20px auto;"
9-
)&attributes(lazyload ? {} : (lazyloadAttrName ? {[lazyloadAttrName.split('=')[0]]: lazyloadAttrName.split('=')[1] === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (lazyloadAttrName.split('=')[1] === '__image__' ? 'https:' + item.cover.replace(/^https:/, '') : (lazyloadAttrName.split('=')[1] || ''))} : {}))
10+
)
1011
.bangumi-info
1112
.bangumi-title
1213
a(target="_blank" href='https://bangumi.tv/subject/' + item.id)= item.title || __('unknown')

lib/templates/bgmv0-template.pug

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
.bangumi-item
22
.bangumi-picture
33
img(
4-
src=lazyload ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (srcValue === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : 'https:' + item.cover.replace(/^https:/, ''))
4+
src=('https:' + item.cover.replace(/^https:/, ''))
55
data-src=lazyload ? item.cover : null
66
referrerpolicy="no-referrer"
7+
loading=lazyload ? "lazy" : "eager"
78
width="110"
89
style="width:110px;margin:20px auto;"
910
)

lib/templates/bili-template.pug

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.bangumi-item
22
.bangumi-picture
33
img(
4-
src=lazyload ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (srcValue === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : 'https:' + item.cover.replace(/^https:/, ''))
5-
data-src=lazyload ? item.cover : null
4+
src=('https:' + item.cover.replace(/^https:/, ''))
65
referrerpolicy="no-referrer"
6+
loading=lazyload ? "lazy" : "eager"
77
width="110"
88
style="width:110px;margin:20px auto;"
9-
)&attributes(lazyloadAttrName ? {[lazyloadAttrName.split('=')[0]]: lazyloadAttrName.split('=')[1] === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (lazyloadAttrName.split('=')[1] === '__image__' ? 'https:' + item.cover.replace(/^https:/, '') : (lazyloadAttrName.split('=')[1] || ''))} : {})
9+
)
1010
.bangumi-info
1111
.bangumi-title
1212
a(target="_blank" href=item.link || ('https://www.bilibili.com/bangumi/media/md' + item.id + '/'))=item.title || __('unknown')

lib/templates/simkl-template.pug

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
.bangumi-item
22
.bangumi-picture
33
img(
4-
src=lazyload ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (srcValue === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : 'https:' + item.cover.replace(/^https:/, ''))
5-
data-src=lazyload ? item.cover : null
4+
src=('https:' + item.cover.replace(/^https:/, ''))
65
referrerpolicy="no-referrer"
6+
loading="lazy"
77
width="110"
88
height="160"
99
style="width:110px;margin:10px auto;"
10-
)&attributes(lazyloadAttrName ? {[lazyloadAttrName.split('=')[0]]: lazyloadAttrName.split('=')[1] === '__loading__' ? (loading || "https://cdn.jsdelivr.net/npm/hexo-bilibili-bangumi@1.2.0/lib/img/loading.gif") : (lazyloadAttrName.split('=')[1] === '__image__' ? 'https:' + item.cover.replace(/^https:/, '') : (lazyloadAttrName.split('=')[1] || ''))} : {})
10+
)
1111
.bangumi-info
1212
.bangumi-title
1313
a(target="_blank" href=item.link || ('https://simkl.com/anime/' + item.id + '/'))=item.title || __('unknown')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hexo-bilibili-bangumi",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "hexo bilibili番剧页",
55
"main": "index.js",
66
"scripts": {

src/lib/bangumi-generator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @Author : HCLonely
33
* @Date : 2024-09-11 15:40:57
4-
* @LastEditTime : 2025-07-10 17:50:02
4+
* @LastEditTime : 2025-08-15 09:58:47
55
* @LastEditors : HCLonely
66
* @FilePath : /hexo-bilibili-bangumi/src/lib/bangumi-generator.js
77
* @Description : Hexo页面生成器模块,负责生成番剧、影视和游戏的展示页面。
@@ -86,11 +86,11 @@ module.exports = async function (locals, type = 'bangumi') {
8686
const contents = await pug.renderFile(path.join(__dirname, 'templates/bangumi.pug'), {
8787
quote: config[type].quote,
8888
show: config[type].show || 1,
89-
loading: config[type].loading,
89+
// loading: config[type].loading,
9090
metaColor: config[type].metaColor,
9191
color: config[type].color,
9292
lazyload: config[type].lazyload ?? true,
93-
lazyloadAttrName: config[type].lazyloadAttrName,
93+
// lazyloadAttrName: config[type].lazyloadAttrName,
9494
srcValue: config[type].srcValue || '__image__',
9595
source: config[type].source ?? 'bili',
9696
showMyComment: config[type].showMyComment ?? false,

0 commit comments

Comments
 (0)