mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-08-09 03:58:51 +08:00
feat(shuoshuo): render hexo tag plugins and defer post features via event
This commit is contained in:
@@ -161,7 +161,7 @@
|
||||
container.innerHTML = content
|
||||
|
||||
window.lazyLoadInstance && window.lazyLoadInstance.update()
|
||||
btf.loadLightbox(document.querySelectorAll('#article-container img:not(.no-lightbox)'))
|
||||
document.dispatchEvent(new Event('shuoshuo:rendered'))
|
||||
}
|
||||
|
||||
const setupNavEvents = (nav) => {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hexo-theme-butterfly",
|
||||
"version": "5.6.1",
|
||||
"version": "5.6.2",
|
||||
"description": "A Simple and Card UI Design theme for Hexo",
|
||||
"main": "package.json",
|
||||
"scripts": {
|
||||
|
||||
+20
-1
@@ -157,8 +157,27 @@ hexo.extend.helper.register('shuoshuoFN', (data, page) => {
|
||||
processedData.forEach(item => {
|
||||
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')
|
||||
// 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 = item.content.replace(/<!--CODEBLOCK_(\d+)-->/g, (_, i) => codeBlocks[+i])
|
||||
})
|
||||
|
||||
return processedData
|
||||
|
||||
+6
-1
@@ -995,8 +995,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
GLOBAL_CONFIG_SITE.pageType === 'home' && scrollDownInIndex()
|
||||
scrollFn()
|
||||
|
||||
if (GLOBAL_CONFIG_SITE.pageType !== 'shuoshuo') {
|
||||
forPostFn()
|
||||
GLOBAL_CONFIG_SITE.pageType !== 'shuoshuo' && btf.switchComments(document)
|
||||
btf.switchComments(document)
|
||||
}
|
||||
|
||||
openMobileMenu()
|
||||
}
|
||||
|
||||
@@ -1012,4 +1015,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
fn()
|
||||
})
|
||||
})
|
||||
|
||||
document.addEventListener('shuoshuo:rendered', forPostFn)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user