mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
fix: 修復 lazyload 報 undefined 的 bug close #532
This commit is contained in:
parent
531269c60e
commit
c48ce9af8c
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hexo-theme-butterfly",
|
"name": "hexo-theme-butterfly",
|
||||||
"version": "3.7.5-b2",
|
"version": "3.7.5-b3",
|
||||||
"description": "A Simple and Card UI Design theme for Hexo",
|
"description": "A Simple and Card UI Design theme for Hexo",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ const logger = require('hexo-log')()
|
|||||||
|
|
||||||
hexo.extend.filter.register('before_generate', () => {
|
hexo.extend.filter.register('before_generate', () => {
|
||||||
// Get first two digits of the Hexo version number
|
// Get first two digits of the Hexo version number
|
||||||
var hexoVer = hexo.version.replace(/(^.*\..*)\..*/, '$1')
|
const hexoVer = hexo.version.replace(/(^.*\..*)\..*/, '$1')
|
||||||
|
|
||||||
if (hexoVer < 5) {
|
if (hexoVer < 5) {
|
||||||
logger.error('Please update Hexo to V5.0.0 or higher!')
|
logger.error('Please update Hexo to V5.0.0 or higher!')
|
||||||
|
|||||||
@ -8,20 +8,22 @@
|
|||||||
|
|
||||||
const urlFor = require('hexo-util').url_for.bind(hexo)
|
const urlFor = require('hexo-util').url_for.bind(hexo)
|
||||||
|
|
||||||
if (!hexo.config.theme_config.lazyload.enable) return
|
|
||||||
|
|
||||||
function lazyload (htmlContent) {
|
function lazyload (htmlContent) {
|
||||||
const bg = hexo.theme.config.lazyload.placeholder ? urlFor(hexo.theme.config.lazyload.placeholder) : 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs='
|
const bg = hexo.theme.config.lazyload.placeholder ? urlFor(hexo.theme.config.lazyload.placeholder) : 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs='
|
||||||
return htmlContent.replace(/(<img.*? src=)/ig, `$1 "${bg}" data-lazy-src=`)
|
return htmlContent.replace(/(<img.*? src=)/ig, `$1 "${bg}" data-lazy-src=`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hexo.config.theme_config.lazyload.field === 'site') {
|
hexo.extend.filter.register('after_render:html', function (data) {
|
||||||
hexo.extend.filter.register('after_render:html', function (data) {
|
const config = hexo.theme.config.lazyload
|
||||||
return lazyload.call(this, data)
|
if (!config.enable) return
|
||||||
})
|
if (config.field !== 'site') return
|
||||||
} else {
|
return lazyload.call(this, data)
|
||||||
hexo.extend.filter.register('after_post_render', data => {
|
})
|
||||||
data.content = lazyload.call(this, data.content)
|
|
||||||
return data
|
hexo.extend.filter.register('after_post_render', data => {
|
||||||
})
|
const config = hexo.theme.config.lazyload
|
||||||
}
|
if (!config.enable) return
|
||||||
|
if (config.field !== 'post') return
|
||||||
|
data.content = lazyload.call(this, data.content)
|
||||||
|
return data
|
||||||
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user