diff --git a/package.json b/package.json index 58dc5d0..e5c3727 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-butterfly", - "version": "3.7.5-b2", + "version": "3.7.5-b3", "description": "A Simple and Card UI Design theme for Hexo", "main": "package.json", "scripts": { diff --git a/scripts/events/init.js b/scripts/events/init.js index c198e9e..76f78ef 100644 --- a/scripts/events/init.js +++ b/scripts/events/init.js @@ -2,7 +2,7 @@ const logger = require('hexo-log')() hexo.extend.filter.register('before_generate', () => { // Get first two digits of the Hexo version number - var hexoVer = hexo.version.replace(/(^.*\..*)\..*/, '$1') + const hexoVer = hexo.version.replace(/(^.*\..*)\..*/, '$1') if (hexoVer < 5) { logger.error('Please update Hexo to V5.0.0 or higher!') diff --git a/scripts/filters/post_lazyload.js b/scripts/filters/post_lazyload.js index 7c02bc9..0b21de9 100644 --- a/scripts/filters/post_lazyload.js +++ b/scripts/filters/post_lazyload.js @@ -8,20 +8,22 @@ const urlFor = require('hexo-util').url_for.bind(hexo) -if (!hexo.config.theme_config.lazyload.enable) return - function lazyload (htmlContent) { const bg = hexo.theme.config.lazyload.placeholder ? urlFor(hexo.theme.config.lazyload.placeholder) : 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs=' return htmlContent.replace(/( { - data.content = lazyload.call(this, data.content) - return data - }) -} \ No newline at end of file +hexo.extend.filter.register('after_render:html', function (data) { + const config = hexo.theme.config.lazyload + if (!config.enable) return + if (config.field !== 'site') return + return lazyload.call(this, 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 +})