mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-10 21:17:07 +08:00
feat: 適配 hexo-blog-encrypt fix: 修復 hexo 新版本下,prismjs 的問題 improvement: 在 pjax 關閉的情況下。減少不必要的全局變量 improvement: 更新依賴版本 improvement: 頁面進入效果優化 improvement: 添加平滑滾動 improvement: 兼容性優化 improvement: 優化 lighthouse 分數 improvement: 優化代碼
45 lines
1.5 KiB
Plaintext
45 lines
1.5 KiB
Plaintext
//- Mathjax 3
|
|
script.
|
|
(() => {
|
|
const loadMathjax = () => {
|
|
if (!window.MathJax) {
|
|
window.MathJax = {
|
|
tex: {
|
|
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
|
tags: 'ams'
|
|
},
|
|
chtml: {
|
|
scale: 1.1
|
|
},
|
|
options: {
|
|
renderActions: {
|
|
findScript: [10, doc => {
|
|
for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
|
|
const display = !!node.type.match(/; *mode=display/)
|
|
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
|
|
const text = document.createTextNode('')
|
|
node.parentNode.replaceChild(text, node)
|
|
math.start = {node: text, delim: '', n: 0}
|
|
math.end = {node: text, delim: '', n: 0}
|
|
doc.math.push(math)
|
|
}
|
|
}, '']
|
|
}
|
|
}
|
|
}
|
|
|
|
const script = document.createElement('script')
|
|
script.src = '!{url_for(theme.asset.mathjax)}'
|
|
script.id = 'MathJax-script'
|
|
script.async = true
|
|
document.head.appendChild(script)
|
|
} else {
|
|
MathJax.startup.document.state(0)
|
|
MathJax.texReset()
|
|
MathJax.typesetPromise()
|
|
}
|
|
}
|
|
|
|
btf.addGlobalFn('encrypt', loadMathjax, 'mathjax')
|
|
window.pjax ? loadMathjax() : window.addEventListener('load', loadMathjax)
|
|
})() |