hexo-theme-butterfly/scripts/tag/timeline.js
Jerry ffeab5e20c breaking changes: 移除博天api
breaking changes: 移除 waline 的 avatar 和 avatar cdn 配置
feat: anchor 不再限制 post 頁開啟,可以在任何頁面開啟
feat: 文章標題支持點擊跳轉到此標題開始閲讀 closed #653
feat: toc可以設置全部展開 closed #709
feat: 增加 新的評論系統 giscus
feat: 支持新的評論名寫法,主題會處理評論名字大小寫,舊的會兼容
feat: 友情鏈接列表增加 fetch url 獲取
improvement: 鼠標移到最新評論內容,增加 title 顯示
fix: 修復 rightside 遮擋內容,導致內容無法點擊的 bug
fix: 修復 mermaid 在某些頁面(有元素 id 為 mermaid 時) 會無法加載的 bug
fix: 修復 搜索框不會自動 focus 的 bug
2021-11-14 17:50:11 +08:00

39 lines
1.2 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 = ''
if (args.length) {
args = hexo.render.renderSync({ text: args.join(' '), engine: 'markdown' })
result += `<div class='timeline-item headline'><div class='timeline-item-title'><div class='item-circle'>${args}</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">${result}</div>`
}
hexo.extend.tag.register('timeline', timeLineFn, { ends: true })