mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
feat: 置頂圖標改為在標題左側 feat: 可配置打賞按鈕的文字 feat: 側邊欄增加 系列文章顯示 feat: 增加 series 系列文章 標籤外掛 feat: 移除 addthis 分享 improvement: 代碼優化 improvement: tabs 標籤外掛的回到頂部箭頭位置調整 improvement: 更新 plugin.yml
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
/**
|
|
* timeline
|
|
* by Jerry
|
|
*/
|
|
|
|
'use strict'
|
|
|
|
const timeLineFn = (args, content) => {
|
|
const tlBlock = /<!--\s*timeline (.*?)\s*-->\n([\w\W\s\S]*?)<!--\s*endtimeline\s*-->/g
|
|
|
|
let result = ''
|
|
let color = ''
|
|
let text = ''
|
|
if (args.length) {
|
|
[text, color] = args.join(' ').split(',')
|
|
const mdContent = hexo.render.renderSync({ text, engine: 'markdown' })
|
|
result += `<div class='timeline-item headline'><div class='timeline-item-title'><div class='item-circle'>${mdContent}</div></div></div>`
|
|
}
|
|
|
|
const matches = []
|
|
let match
|
|
|
|
while ((match = tlBlock.exec(content)) !== null) {
|
|
matches.push(match[1])
|
|
matches.push(match[2])
|
|
}
|
|
|
|
for (let i = 0; i < matches.length; i += 2) {
|
|
const tlChildTitle = hexo.render.renderSync({ text: matches[i], engine: 'markdown' })
|
|
const tlChildContent = hexo.render.renderSync({ text: matches[i + 1], engine: 'markdown' })
|
|
|
|
const tlTitleHtml = `<div class='timeline-item-title'><div class='item-circle'>${tlChildTitle}</div></div>`
|
|
const tlContentHtml = `<div class='timeline-item-content'>${tlChildContent}</div>`
|
|
|
|
result += `<div class='timeline-item'>${tlTitleHtml + tlContentHtml}</div>`
|
|
}
|
|
|
|
return `<div class="timeline ${color}">${result}</div>`
|
|
}
|
|
|
|
hexo.extend.tag.register('timeline', timeLineFn, { ends: true })
|