hugo-theme-zzo icon indicating copy to clipboard operation
hugo-theme-zzo copied to clipboard

[Enhance] Use short code to reduce page size

Open joyqat opened this issue 4 years ago • 3 comments

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.

joyqat avatar Aug 03 '20 03:08 joyqat

FYI, the same goes for other libraries.

Starting from here

sosiristseng avatar Dec 03 '20 09:12 sosiristseng

This would be a good addition! No point loading libraries that aren't going to be used by all users.

michaeloliverx avatar Dec 15 '20 22:12 michaeloliverx

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.

NullXeronier avatar Dec 15 '21 09:12 NullXeronier