2025-2-26-fixed
This commit is contained in:
20
themes/next/layout/_third-party/math/index.swig
vendored
Normal file
20
themes/next/layout/_third-party/math/index.swig
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
{%- if theme.math.mathjax.enable or theme.math.katex.enable %}
|
||||
{%- set is_index_has_math = false %}
|
||||
|
||||
{# At home, check if there has `mathjax: true` post #}
|
||||
{%- if is_home() and theme.math.per_page %}
|
||||
{%- for post in page.posts.toArray() %}
|
||||
{%- if post.mathjax and not is_index_has_math %}
|
||||
{%- set is_index_has_math = true %}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
{%- endif %}
|
||||
|
||||
{%- if not theme.math.per_page or is_index_has_math or page.mathjax %}
|
||||
{%- if theme.math.mathjax.enable %}
|
||||
{% include '_third-party/math/mathjax.swig' %}
|
||||
{% elif theme.math.katex.enable %}
|
||||
{% include '_third-party/math/katex.swig' %}
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
8
themes/next/layout/_third-party/math/katex.swig
vendored
Normal file
8
themes/next/layout/_third-party/math/katex.swig
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
{%- set katex_uri = theme.vendors.katex or '//cdn.jsdelivr.net/npm/katex@0/dist/katex.min.css' %}
|
||||
<link rel="stylesheet" href="{{ katex_uri }}">
|
||||
{%- if theme.math.katex.copy_tex %}
|
||||
{%- set copy_tex_js_uri = theme.vendors.copy_tex_js or '//cdn.jsdelivr.net/npm/katex@0/dist/contrib/copy-tex.min.js' %}
|
||||
{%- set copy_tex_css_uri = theme.vendors.copy_tex_css or '//cdn.jsdelivr.net/npm/katex@0/dist/contrib/copy-tex.min.css' %}
|
||||
<script src="{{ copy_tex_js_uri }}"></script>
|
||||
<link rel="stylesheet" href="{{ copy_tex_css_uri }}">
|
||||
{%- endif %}
|
||||
57
themes/next/layout/_third-party/math/mathjax.swig
vendored
Normal file
57
themes/next/layout/_third-party/math/mathjax.swig
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
{%- set mathjax_uri = theme.vendors.mathjax or '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js' %}
|
||||
|
||||
<script>
|
||||
if (typeof MathJax === 'undefined') {
|
||||
window.MathJax = {
|
||||
loader: {
|
||||
{%- if theme.math.mathjax.mhchem %}
|
||||
load: ['[tex]/mhchem'],
|
||||
{%- endif %}
|
||||
source: {
|
||||
'[tex]/amsCd': '[tex]/amscd',
|
||||
'[tex]/AMScd': '[tex]/amscd'
|
||||
}
|
||||
},
|
||||
tex: {
|
||||
inlineMath: {'[+]': [['$', '$']]},
|
||||
{%- if theme.math.mathjax.mhchem %}
|
||||
packages: {'[+]': ['mhchem']},
|
||||
{%- endif %}
|
||||
tags: 'ams'
|
||||
},
|
||||
options: {
|
||||
renderActions: {
|
||||
findScript: [10, doc => {
|
||||
document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
|
||||
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);
|
||||
});
|
||||
}, '', false],
|
||||
insertedScript: [200, () => {
|
||||
document.querySelectorAll('mjx-container').forEach(node => {
|
||||
let target = node.parentNode;
|
||||
if (target.nodeName.toLowerCase() === 'li') {
|
||||
target.parentNode.classList.add('has-jax');
|
||||
}
|
||||
});
|
||||
}, '', false]
|
||||
}
|
||||
}
|
||||
};
|
||||
(function () {
|
||||
var script = document.createElement('script');
|
||||
script.src = '{{ mathjax_uri }}';
|
||||
script.defer = true;
|
||||
document.head.appendChild(script);
|
||||
})();
|
||||
} else {
|
||||
MathJax.startup.document.state(0);
|
||||
MathJax.texReset();
|
||||
MathJax.typeset();
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user