Breaking Changes: lazyload 優化 (增加高斯模糊過度特效,增加配置 lazyload 範圍,佔位圖應用到全站)

Breaking Changes: site_verification 優化,需自行配置
This commit is contained in:
Jerry
2021-03-24 21:57:30 +08:00
Unverified
parent 4b381350a1
commit 6057297f44
16 changed files with 55 additions and 83 deletions
+17 -6
View File
@@ -8,9 +8,20 @@
const urlFor = require('hexo-util').url_for.bind(hexo)
hexo.extend.filter.register('after_post_render', data => {
if (!hexo.theme.config.lazyload.enable) return
const bg = hexo.theme.config.lazyload.post ? urlFor(hexo.theme.config.lazyload.post) : 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs='
data.content = data.content.replace(/(<img.*? src=)/ig, `$1 "${bg}" data-lazy-src=`)
return data
})
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(/(<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) {
return lazyload.call(this, data)
})
} else {
hexo.extend.filter.register('after_post_render', data => {
data.content = lazyload.call(this, data.content)
return data
})
}
+1 -4
View File
@@ -41,7 +41,6 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
const limitNum = config.related_post.limit || 6
const dateType = config.related_post.date_type || 'created'
const headlineLang = this._p('post.recommend')
const lazySrc = config.lazyload.enable ? 'data-lazy-src' : 'src'
relatedPosts = relatedPosts.sort(compare('weight'))
@@ -67,9 +66,7 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
relatedPosts[i].title +
'">'
result +=
'<img class="cover" ' +
lazySrc +
'="' +
'<img class="cover" src="' +
this.url_for(cover) +
'" alt="cover">'
if (dateType === 'created') {