feat(shuoshuo): render hexo tag plugins and defer post features via event

This commit is contained in:
myw
2026-07-21 21:46:58 +08:00 Unverified
parent 77ec898737
commit 85a1412b94
4 changed files with 65 additions and 41 deletions
+1 -1
View File
@@ -161,7 +161,7 @@
container.innerHTML = content container.innerHTML = content
window.lazyLoadInstance && window.lazyLoadInstance.update() window.lazyLoadInstance && window.lazyLoadInstance.update()
btf.loadLightbox(document.querySelectorAll('#article-container img:not(.no-lightbox)')) document.dispatchEvent(new Event('shuoshuo:rendered'))
} }
const setupNavEvents = (nav) => { const setupNavEvents = (nav) => {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hexo-theme-butterfly", "name": "hexo-theme-butterfly",
"version": "5.6.1", "version": "5.6.2",
"description": "A Simple and Card UI Design theme for Hexo", "description": "A Simple and Card UI Design theme for Hexo",
"main": "package.json", "main": "package.json",
"scripts": { "scripts": {
+20 -1
View File
@@ -157,8 +157,27 @@ hexo.extend.helper.register('shuoshuoFN', (data, page) => {
processedData.forEach(item => { processedData.forEach(item => {
const parsed = moment.utc(item.date) const parsed = moment.utc(item.date)
item.date = moment.tz(parsed.format('YYYY-MM-DD HH:mm:ss'), timezone).format('YYYY-MM-DD HH:mm:ss') item.date = moment.tz(parsed.format('YYYY-MM-DD HH:mm:ss'), timezone).format('YYYY-MM-DD HH:mm:ss')
// markdown
// Render the content using Hexo's rendering engine to process any tags or markdown
const mockPost = { content: item.content }
hexo.execFilterSync('before_post_render', mockPost, { context: hexo })
item.content = mockPost.content
const codeBlocks = []
item.content = item.content.replace(/<hexoPostRenderCodeBlock>([\s\S]*?)<\/hexoPostRenderCodeBlock>/g, (_, c) => {
codeBlocks.push(c)
return `<!--CODEBLOCK_${codeBlocks.length - 1}-->`
})
try {
item.content = hexo.extend.tag.env.renderString(item.content, {})
} catch (e) {
// ignore tag plugin errors, fallback to markdown-only rendering
}
item.content = hexo.render.renderSync({ text: item.content, engine: 'markdown' }) item.content = hexo.render.renderSync({ text: item.content, engine: 'markdown' })
item.content = item.content.replace(/<!--CODEBLOCK_(\d+)-->/g, (_, i) => codeBlocks[+i])
}) })
return processedData return processedData
+7 -2
View File
@@ -995,8 +995,11 @@ document.addEventListener('DOMContentLoaded', () => {
GLOBAL_CONFIG_SITE.pageType === 'home' && scrollDownInIndex() GLOBAL_CONFIG_SITE.pageType === 'home' && scrollDownInIndex()
scrollFn() scrollFn()
forPostFn() if (GLOBAL_CONFIG_SITE.pageType !== 'shuoshuo') {
GLOBAL_CONFIG_SITE.pageType !== 'shuoshuo' && btf.switchComments(document) forPostFn()
btf.switchComments(document)
}
openMobileMenu() openMobileMenu()
} }
@@ -1012,4 +1015,6 @@ document.addEventListener('DOMContentLoaded', () => {
fn() fn()
}) })
}) })
document.addEventListener('shuoshuo:rendered', forPostFn)
}) })