hugo-soresu

My fork of hugo-xmin

git clone git://git.shimmy1996.com/hugo-soresu.git
commit 540e0332894822168f990f03149010b734ec663d
parent c5e0a4584c240057988eeaaa0975fc6113cf89b4
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date:   Mon, 28 May 2018 22:15:24 -0500

Add option for KaTeX, move css links to revelant partials, and inline small js.

Diffstat:
Mlayouts/partials/comment.html | 1+
Mlayouts/partials/footer.html | 2+-
Mlayouts/partials/header.html | 2+-
Dlayouts/partials/include_css.html | 3---
Dlayouts/partials/include_js.html | 2--
Alayouts/partials/katex.html | 26++++++++++++++++++++++++++
Alayouts/partials/mathjax.html | 23+++++++++++++++++++++++
Alayouts/partials/stylesheet.html | 2++
Dstatic/js/math-code.js | 20--------------------
9 files changed, 54 insertions(+), 27 deletions(-)
diff --git a/layouts/partials/comment.html b/layouts/partials/comment.html
@@ -1,4 +1,5 @@
 <hr/>
+<link rel="stylesheet" href="{{ "/css/isso.css" | relURL }}" type="text/css" />
 <script data-isso="/isso/"
         data-isso-css="false"
         data-isso-lang={{ .Site.Language }}
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
@@ -1,6 +1,6 @@
 <hr/>
 <footer>
-  {{ partial "include_js.html" . }}
+  {{ partial "katex.html" . }}
   {{ with .Site.Copyright }} {{ . | markdownify }} {{ end }}
 </footer>
 </body>
diff --git a/layouts/partials/header.html b/layouts/partials/header.html
@@ -3,8 +3,8 @@
 <head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
-  {{ partial "include_css.html" . }}
   {{ partial "favicon.html" . }}
+  {{ partial "stylesheet.html" . }}
   {{ $title := i18n (lower .Title) }}
   {{ if eq $title "" }}
     <title>{{.Title}} | {{.Site.Title}}</title>
diff --git a/layouts/partials/include_css.html b/layouts/partials/include_css.html
@@ -1,3 +0,0 @@
-<link rel="stylesheet" href="{{ "/css/isso.css" | relURL }}" type="text/css" />
-<link rel="stylesheet" href="{{ "/css/style.css" | relURL }}" type="text/css" />
-<link rel="stylesheet" href="{{ "/css/fonts.css" | relURL }}" type="text/css" />
diff --git a/layouts/partials/include_js.html b/layouts/partials/include_js.html
@@ -1,2 +0,0 @@
-<script type="text/javascript" src="/js/math-code.js"></script>
-<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_CHTML" integrity="sha256-GhM+5JHb6QUzOQPXSJLEWP7R73CbkisjzK5Eyij4U9w=" crossorigin="anonymous"></script>
diff --git a/layouts/partials/katex.html b/layouts/partials/katex.html
@@ -0,0 +1,26 @@
+<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-alpha/dist/katex.min.css" integrity="sha384-BTL0nVi8DnMrNdMQZG1Ww6yasK9ZGnUxL1ZWukXQ7fygA1py52yPp9W4wrR00VML" crossorigin="anonymous">
+<script src="https://cdn.jsdelivr.net/npm/katex@0.10.0-alpha/dist/katex.min.js" integrity="sha384-y6SGsNt7yZECc4Pf86XmQhC4hG2wxL6Upkt9N1efhFxfh6wlxBH0mJiTE8XYclC1" crossorigin="anonymous"></script>
+<script src="https://cdn.jsdelivr.net/npm/katex@0.10.0-alpha/dist/contrib/auto-render.min.js" integrity="sha384-IiI65aU9ZYub2MY9zhtKd1H2ps7xxf+eb2YFG9lX6uRqpXCvBTOidPRCXCrQ++Uc" crossorigin="anonymous"></script>
+<script type="text/javascript">
+(function() {
+  var i, text, code, codes = document.getElementsByTagName('code');
+  for (i = 0; i < codes.length;) {
+    code = codes[i];
+    if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
+      text = code.textContent;
+      if (/^\$[^$]/.test(text) && /[^$]\$$/.test(text)) {
+        text = text.replace(/^\$/, '\\(').replace(/\$$/, '\\)');
+        code.textContent = text;
+      }
+      if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
+          /^\$(.|\s)+\$$/.test(text) ||
+          /^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
+        code.outerHTML = code.innerHTML;  // remove <code></code>
+        continue;
+      }
+    }
+    i++;
+  }
+})();
+renderMathInElement(document.body);
+</script>
diff --git a/layouts/partials/mathjax.html b/layouts/partials/mathjax.html
@@ -0,0 +1,23 @@
+<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_CHTML" integrity="sha256-GhM+5JHb6QUzOQPXSJLEWP7R73CbkisjzK5Eyij4U9w=" crossorigin="anonymous"></script>
+<script type="text/javascript">
+(function() {
+  var i, text, code, codes = document.getElementsByTagName('code');
+  for (i = 0; i < codes.length;) {
+    code = codes[i];
+    if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
+      text = code.textContent;
+      if (/^\$[^$]/.test(text) && /[^$]\$$/.test(text)) {
+        text = text.replace(/^\$/, '\\(').replace(/\$$/, '\\)');
+        code.textContent = text;
+      }
+      if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
+          /^\$(.|\s)+\$$/.test(text) ||
+          /^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
+        code.outerHTML = code.innerHTML;  // remove <code></code>
+        continue;
+      }
+    }
+    i++;
+  }
+})();
+</script>
diff --git a/layouts/partials/stylesheet.html b/layouts/partials/stylesheet.html
@@ -0,0 +1,2 @@
+<link rel="stylesheet" href="{{ "/css/style.css" | relURL }}" type="text/css" />
+<link rel="stylesheet" href="{{ "/css/fonts.css" | relURL }}" type="text/css" />
diff --git a/static/js/math-code.js b/static/js/math-code.js
@@ -1,20 +0,0 @@
-(function() {
-  var i, text, code, codes = document.getElementsByTagName('code');
-  for (i = 0; i < codes.length;) {
-    code = codes[i];
-    if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
-      text = code.textContent;
-      if (/^\$[^$]/.test(text) && /[^$]\$$/.test(text)) {
-        text = text.replace(/^\$/, '\\(').replace(/\$$/, '\\)');
-        code.textContent = text;
-      }
-      if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
-          /^\$(.|\s)+\$$/.test(text) ||
-          /^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
-        code.outerHTML = code.innerHTML;  // remove <code></code>
-        continue;
-      }
-    }
-    i++;
-  }
-})();