mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-08-08 19:48:42 +08:00
feat(shuoshuo): render hexo tag plugins and defer post features via event
This commit is contained in:
+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
|
||||
|
||||
Reference in New Issue
Block a user