mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-06-05 21:01:46 +08:00
pjax
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
|
||||
@@ -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'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user