From b14ca5d15b221e95af57b37d30f79905946b2a1c Mon Sep 17 00:00:00 2001
From: Jimmy Cai <jimmehcai@gmail.com>
Date: Mon, 21 Sep 2020 16:22:44 +0200
Subject: [PATCH] feat(article): add KaTeX support

---
 exampleSite/config.toml                       | 1 +
 layouts/partials/article/article.html         | 4 ++++
 layouts/partials/article/components/math.html | 8 ++++++++
 3 files changed, 13 insertions(+)
 create mode 100644 layouts/partials/article/components/math.html

diff --git a/exampleSite/config.toml b/exampleSite/config.toml
index d554f8c..16fb678 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -21,6 +21,7 @@ DefaultContentLanguage = "en"                   # Theme i18n support
         avatar = "img/avatar.png"
         subtitle = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
     [params.article]
+        math = false
         [params.article.license]
             enabled = true 
             default = "Licenced under CC BY-NC-SA 4.0"
diff --git a/layouts/partials/article/article.html b/layouts/partials/article/article.html
index 1f453aa..f3f7e90 100644
--- a/layouts/partials/article/article.html
+++ b/layouts/partials/article/article.html
@@ -4,4 +4,8 @@
     {{ partial "article/components/content" . }}
 
     {{ partial "article/components/footer" . }}
+
+    {{ if or .Params.math .Site.Params.article.math }}
+        {{ partialCached "article/components/math.html" . }}
+    {{ end }}
 </article>
\ No newline at end of file
diff --git a/layouts/partials/article/components/math.html b/layouts/partials/article/components/math.html
new file mode 100644
index 0000000..6c4d3fd
--- /dev/null
+++ b/layouts/partials/article/components/math.html
@@ -0,0 +1,8 @@
+<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css"
+    integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
+<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js"
+    integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4"
+    crossorigin="anonymous"></script>
+<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js"
+    integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"
+    onload="renderMathInElement(document.querySelector(`.article-content`));"></script>
\ No newline at end of file