From a696ebdc6839153521e0aa1a17e6e280199d60bc Mon Sep 17 00:00:00 2001
From: Eduardo Trujillo <ed@chromabits.com>
Date: Sun, 5 Nov 2017 16:25:10 -0800
Subject: [PATCH] refactor(MathJax): Serve from blog server rather than using
 outdated CDN

---
 .gitmodules            |  3 +++
 src/site.hs            | 11 +++++++++++
 templates/default.html |  2 +-
 third_party/mathjax    |  1 +
 4 files changed, 16 insertions(+), 1 deletion(-)
 create mode 160000 third_party/mathjax

diff --git a/.gitmodules b/.gitmodules
index 7b9c858..873a633 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -7,3 +7,6 @@
 [submodule "third_party/foundation-sites"]
 	path = third_party/foundation-sites
 	url = https://github.com/zurb/foundation-sites.git
+[submodule "third_party/mathjax"]
+	path = third_party/mathjax
+	url = https://github.com/mathjax/MathJax.git
diff --git a/src/site.hs b/src/site.hs
index 53c69a6..51c5dd0 100644
--- a/src/site.hs
+++ b/src/site.hs
@@ -91,6 +91,12 @@ main = hakyllServeWith serveConf $ do
   match "third_party/font-awesome/fonts/*" $ do
     route $ gsubRoute "third_party/font-awesome/" (const "")
     compile copyFileCompiler
+  mapM_ matchThirdPartyJSAndCopy
+    [ "third_party/mathjax/MathJax.js"
+    , "third_party/mathjax/config/**"
+    , "third_party/mathjax/extensions/**"
+    , "third_party/mathjax/jax/**"
+    ]
 
   create ["scss/app.scss"] $ do
     route $ gsubRoute "scss/" (const "css/") `composeRoutes` setExtension "css"
@@ -332,6 +338,11 @@ matchAndCopy (path, extension) = match path $ do
   route $ dropContentPrefix `composeRoutes` setExtension extension
   compile copyFileCompiler
 
+matchThirdPartyJSAndCopy :: Pattern -> Rules ()
+matchThirdPartyJSAndCopy dir = match dir $ do
+  route $ gsubRoute "third_party/" (const "js/")
+  compile copyFileCompiler
+
 -- IDENTIFIER HELPERS ---------------------------------------------------------
 
 grouper :: MonadMetadata m => [Identifier] -> m [[Identifier]]
diff --git a/templates/default.html b/templates/default.html
index 08adf37..caafaf5 100644
--- a/templates/default.html
+++ b/templates/default.html
@@ -119,7 +119,7 @@
     </div>
 
     <script async type="text/javascript"
-        src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
+        src="/js/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
     </script>
   </body>
 </html>
diff --git a/third_party/mathjax b/third_party/mathjax
new file mode 160000
index 0000000..8259006
--- /dev/null
+++ b/third_party/mathjax
@@ -0,0 +1 @@
+Subproject commit 82590066f9cc3561d4a6b6355ce82af324cb161d
-- 
GitLab