mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
fix: 修復首頁文章 valine 評論數只顯示第一篇的 bug fix: 修復子目錄下,第三方插件本地資源無法加載的 bug closed #908 fix: 評論系統開啟時 busuanzi 的 page_pv 不顯示的 bug closed #902 fix: 修復 pjax 下,使用 mermaid 跳轉會重新加載的 bug
26 lines
1.1 KiB
Plaintext
26 lines
1.1 KiB
Plaintext
script.
|
|
(() => {
|
|
const $mermaidWrap = document.querySelectorAll('#article-container .mermaid-wrap')
|
|
if ($mermaidWrap.length) {
|
|
window.runMermaid = () => {
|
|
window.loadMermaid = true
|
|
const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? '!{theme.mermaid.theme.dark}' : '!{theme.mermaid.theme.light}'
|
|
|
|
Array.from($mermaidWrap).forEach((item, index) => {
|
|
const mermaidSrc = item.firstElementChild
|
|
const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
|
|
const mermaidID = 'mermaid-' + index
|
|
const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent
|
|
mermaid.mermaidAPI.render(mermaidID, mermaidDefinition, (svgCode) => {
|
|
mermaidSrc.insertAdjacentHTML('afterend', svgCode)
|
|
})
|
|
})
|
|
}
|
|
|
|
const loadMermaid = () => {
|
|
window.loadMermaid ? runMermaid() : getScript('!{url_for(theme.asset.mermaid)}').then(runMermaid)
|
|
}
|
|
|
|
window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
|
|
}
|
|
})() |