fix theme...

This commit is contained in:
2024-08-01 08:43:15 +08:00
parent 192ef21b12
commit 02130fba76
371 changed files with 28176 additions and 3285 deletions

View File

@@ -0,0 +1,18 @@
if theme.mathjax && theme.mathjax.enable
if theme.mathjax.per_page
if is_post() || is_page()
include ./mathjax.pug
else
if page.mathjax
include ./mathjax.pug
if theme.katex && theme.katex.enable
if theme.katex.per_page
if is_post() || is_page()
include ./katex.pug
else
if page.katex
include ./katex.pug
if theme.mermaid.enable
include ./mermaid.pug

View File

@@ -0,0 +1,9 @@
link(rel="stylesheet" type="text/css" href=url_for(theme.asset.katex))
script(src=url_for(theme.asset.katex_copytex))
script.
(() => {
document.querySelectorAll('#article-container span.katex-display').forEach(item => {
anzhiyu.wrap(item, 'div', { class: 'katex-wrap'})
})
})()

View File

@@ -0,0 +1,38 @@
//- Mathjax 3
script.
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()
}

View File

@@ -0,0 +1,38 @@
script.
(() => {
const $mermaid = document.querySelectorAll('#article-container .mermaid-wrap')
if ($mermaid.length === 0) return
const runMermaid = () => {
window.loadMermaid = true
const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? '!{theme.mermaid.theme.dark}' : '!{theme.mermaid.theme.light}'
Array.from($mermaid).forEach((item, index) => {
const mermaidSrc = item.firstElementChild
const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
const mermaidID = 'mermaid-' + index
const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent
const renderFn = mermaid.render(mermaidID, mermaidDefinition)
const renderV10 = () => {
renderFn.then(({svg}) => {
mermaidSrc.insertAdjacentHTML('afterend', svg)
})
}
const renderV9 = svg => {
mermaidSrc.insertAdjacentHTML('afterend', svg)
}
typeof renderFn === 'string' ? renderV9(renderFn) : renderV10()
})
}
const loadMermaid = () => {
window.loadMermaid ? runMermaid() : getScript('!{url_for(theme.asset.mermaid)}').then(runMermaid)
}
anzhiyu.addGlobalFn('themeChange', runMermaid, 'mermaid')
window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
})()