hexo-theme-butterfly/scripts/tag/timeline.js
Jerry 18d9d652a0 feat: 美化 firefox 瀏覽器滾動條
fix: Utterances 評論區在多個頁面顯示的是同一個評論區
fix: 修復評論配置爲 Livere 和 Facebook Comments 時,最新評論模塊仍然顯示的 bug
improvement: blueimp_md5 CDN 可配置
improvement: timeline 優化
improvement: css優化
improvement: 友情鏈接優化
2022-01-15 00:30:01 +08:00

42 lines
1.3 KiB
JavaScript

/**
* timeline
* by Jerry
*/
'use strict'
function timeLineFn (args, content) {
const tlBlock = /<!--\s*timeline (.*?)\s*-->\n([\w\W\s\S]*?)<!--\s*endtimeline\s*-->/g
let result = ''
let color = ''
if (args.length) {
args = args.join(' ').split(',')
color = args[1]
const mdContent = hexo.render.renderSync({ text: args[0], 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 })