mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-08 12:07:06 +08:00
chore: bump version to 5.5.1 and update dependencies
- Upgrade version from 5.5.0 to 5.5.1 - Update third-party dependencies: algolia, disqusjs, docsearch, fancybox, fontawesome, mermaid - Replace Twitter with X in share configurations - Enable CDN version numbers by default - Fix shuoshuo page JSON security with safeJSON helper - Improve image lazy loading regex to handle minified HTML - Fix search result HTML structure and styling - Add margin-top to search result numbering for better alignment
This commit is contained in:
@@ -290,10 +290,10 @@ module.exports = {
|
||||
share: {
|
||||
use: 'sharejs',
|
||||
sharejs: {
|
||||
sites: 'facebook,twitter,wechat,weibo,qq'
|
||||
sites: 'facebook,x,wechat,weibo,qq'
|
||||
},
|
||||
addtoany: {
|
||||
item: 'facebook,twitter,wechat,sina_weibo,facebook_messenger,email,copy_link'
|
||||
item: 'facebook,x,wechat,sina_weibo,facebook_messenger,email,copy_link'
|
||||
}
|
||||
},
|
||||
comments: {
|
||||
@@ -591,7 +591,7 @@ module.exports = {
|
||||
CDN: {
|
||||
internal_provider: 'local',
|
||||
third_party_provider: 'jsdelivr',
|
||||
version: false,
|
||||
version: true,
|
||||
custom_format: null,
|
||||
option: null
|
||||
}
|
||||
|
||||
@@ -18,20 +18,12 @@ const lazyload = htmlContent => {
|
||||
|
||||
const bg = hexo.theme.config.lazyload.placeholder ? urlFor(hexo.theme.config.lazyload.placeholder) : 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
|
||||
|
||||
// Use more precise replacement: handle src attributes with double and single quotes, but avoid replacing content inside script tags
|
||||
let result = htmlContent
|
||||
|
||||
// Handle src attributes with double quotes
|
||||
result = result.replace(/(<img(?![^>]*?\bdata-lazy-src=)(?:\s[^>]*?)?\ssrc="([^"]+)")(?![^<]*<\/script>)/gi, (match, tag, src) => {
|
||||
return tag.replace(`src="${src}"`, `src="${bg}" data-lazy-src="${src}"`)
|
||||
// Handle src attributes with double quotes, single quotes, or no quotes (unified approach)
|
||||
// Matches: src="..." or src='...' or src=... (e.g., after minification by hexo-minify)
|
||||
return htmlContent.replace(/(<img(?![^>]*?\bdata-lazy-src=)(?:\s[^>]*?)?\ssrc=)(?:"([^"]*)"|'([^']*)'|([^\s>]+))(?![^<]*<\/script>)/gi, (match, prefix, srcDoubleQuote, srcSingleQuote, srcNoQuote) => {
|
||||
const src = srcDoubleQuote || srcSingleQuote || srcNoQuote
|
||||
return `${prefix}"${bg}" data-lazy-src="${src}"`
|
||||
})
|
||||
|
||||
// Handle src attributes with single quotes
|
||||
result = result.replace(/(<img(?![^>]*?\bdata-lazy-src=)(?:\s[^>]*?)?\ssrc='([^']+)')(?![^<]*<\/script>)/gi, (match, tag, src) => {
|
||||
return tag.replace(`src='${src}'`, `src='${bg}' data-lazy-src='${src}'`)
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
hexo.extend.filter.register('after_render:html', data => {
|
||||
|
||||
@@ -157,3 +157,12 @@ hexo.extend.helper.register('getVersion', () => {
|
||||
const { version } = require('../../package.json')
|
||||
return { hexo: hexo.version, theme: version }
|
||||
})
|
||||
|
||||
hexo.extend.helper.register('safeJSON', data => {
|
||||
// Safely serialize JSON for embedding in <script> tags
|
||||
return JSON.stringify(data)
|
||||
.replace(/</g, '\\u003c')
|
||||
.replace(/>/g, '\\u003e')
|
||||
.replace(/\u2028/g, '\\u2028')
|
||||
.replace(/\u2029/g, '\\u2029')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user