hugo-theme-zzo
hugo-theme-zzo copied to clipboard
[Enhance] Use short code to reduce page size
In single-script.html
, unused library code can be eliminated through {{if}}
shortcodes like library loading.
e.g.
if (lib && lib.includes('katex')) {
var mathElements = document.getElementsByClassName('math');
var options = {
delimiters: [
{ left: "$$", right: "$$", display: true },
{ left: "\\[", right: "\\]", display: true },
{ left: "$", right: "$", display: false },
{ left: "\\(", right: "\\)", display: false }
],
};
renderMathInElement(document.querySelector('.single__contents'), options);
}
can be changed into
{{ if in .Params.Libraries "katex" }}
var mathElements = document.getElementsByClassName('math');
var options = {
delimiters: [
{ left: "$$", right: "$$", display: true },
{ left: "\\[", right: "\\]", display: true },
{ left: "$", right: "$", display: false },
{ left: "\\(", right: "\\)", display: false }
],
};
renderMathInElement(document.querySelector('.single__contents'), options);
{{ end }}
In this case the generated file will not contain this block of code if katex library is not enabled, so the page size is reduced.
I could make a PR if this is OK.
This would be a good addition! No point loading libraries that aren't going to be used by all users.
Multi-Line katex NOT working currently.. Well working in official site, but zzo theme does NOT. Is there solutions how to solve multi-Lined katex problem ???
this katex text \mathbf{t} 2 \mathbf{v}(\tau)[i]=\left{\begin{array}{ll} \omega_{i} \tau+\varphi_{i}, & \text { if } i=0 \ \mathcal{F}\left(\omega_{i} \tau+\varphi_{i}\right), & \text { if } 1 \leq i \leq k \end{array}\right.