This commit is contained in:
Jerry
2020-07-16 19:30:54 +08:00
Unverified
parent 5b6e008b84
commit 898cc31c58
93 changed files with 2128 additions and 2151 deletions
+2 -3
View File
@@ -1,9 +1,8 @@
/**
* Butterfly
* lazyload
* replace src to data-src
* replace src to data-lazy-src
*/
// <figure .+class="[^"]* highlight [^"]*".+>
'use strict'
@@ -11,7 +10,7 @@ const urlFor = require('hexo-util').url_for.bind(hexo)
function lazyProcess (htmlContent) {
const bg = hexo.theme.config.lazyload.post ? urlFor(hexo.theme.config.lazyload.post) : 'data:image/gif;base64,R0lGODdhAQABAPAAAMPDwwAAACwAAAAAAQABAAACAkQBADs='
return htmlContent.replace(/(<img .*?src=)/ig, `$1 "${bg}" data-src=`)
return htmlContent.replace(/(<img .*? src=)/ig, `$1 "${bg}" data-lazy-src=`)
}
const processPost = function (data) {
+4
View File
@@ -6,10 +6,14 @@
'use strict'
hexo.extend.filter.register('before_post_render', function (data) {
if (data.top_img && data.top_img.indexOf('/') === -1) data.top_img = data.path + data.top_img
if (data.cover && data.cover.indexOf('/') === -1) data.cover = data.path + data.cover
if (data.cover === false) {
data.randomcover = randomCover()
return data
}
data.cover = data.cover || randomCover()
return data
})
+5
View File
@@ -9,6 +9,7 @@
'use strict'
const { stripHTML, escapeHTML } = require('hexo-util')
const crypto = require('crypto')
hexo.extend.helper.register('page_description', function () {
const { config, page } = this
@@ -56,3 +57,7 @@ hexo.extend.helper.register('urlNoIndex', function () {
}
return url
})
hexo.extend.helper.register('md5', function (path) {
return crypto.createHash('md5').update(decodeURI(this.url_for(path))).digest('hex')
})
+1 -1
View File
@@ -41,7 +41,7 @@ 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-src' : 'src'
const lazySrc = config.lazyload.enable ? 'data-lazy-src' : 'src'
relatedPosts = relatedPosts.sort(compare('weight'))