From cc3a24565f4d357eb8ba83b325b8a2bfd1b8af64 Mon Sep 17 00:00:00 2001 From: Chris Hodapp Date: Thu, 14 Dec 2017 15:07:45 -0500 Subject: [PATCH] Enabled MathJax rendering through Pandoc --- blag.cabal | 2 ++ site.hs | 26 ++++++++++++++++++++++---- templates/default.html | 5 +++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/blag.cabal b/blag.cabal index e4fe62e..95d68ff 100644 --- a/blag.cabal +++ b/blag.cabal @@ -8,5 +8,7 @@ executable site build-depends: base == 4.* , hakyll >= 4.6 , filepath + , containers + , pandoc ghc-options: -threaded default-language: Haskell2010 diff --git a/site.hs b/site.hs index daafff6..2921fc4 100644 --- a/site.hs +++ b/site.hs @@ -10,18 +10,36 @@ Portability : POSIX import Data.Monoid (mappend) import Hakyll import System.FilePath +import Text.Pandoc.Options import qualified GHC.IO.Encoding as E +import qualified Data.Set as S -- | Configuration for the RSS and ATOM feeds. feedConfiguration :: FeedConfiguration feedConfiguration = FeedConfiguration - { feedTitle = "hodapple blog, FIXME!" + { feedTitle = "hodapple blog" , feedDescription = "FIXME!" , feedAuthorName = "Chris Hodapp" , feedAuthorEmail = "Hodapp87@gmail.com" , feedRoot = "http://???" } +-- | Alternate pandocCompiler which enables MathJax +pandocMathCompiler :: Compiler (Item String) +pandocMathCompiler = + -- Lifted straight from: + -- http://travis.athougies.net/posts/2013-08-13-using-math-on-your-hakyll-blog.html + let mathExtensions = [ Ext_tex_math_dollars + , Ext_tex_math_double_backslash + , Ext_latex_macros] + defaultExtensions = writerExtensions defaultHakyllWriterOptions + newExtensions = foldr S.insert defaultExtensions mathExtensions + writerOptions = defaultHakyllWriterOptions { + writerExtensions = newExtensions, + writerHTMLMathMethod = MathJax "" + } + in pandocCompilerWith defaultHakyllReaderOptions writerOptions + -- | Main entry point for generating all code via Hakyll main :: IO () main = do @@ -57,7 +75,7 @@ main = do match "pages/*" $ do route $ setExtension "html" - compile $ pandocCompiler + compile $ pandocMathCompiler >>= loadAndApplyTemplate "templates/default.html" defaultContext >>= relativizeUrls @@ -72,7 +90,7 @@ main = do match "posts/*" $ do route $ setExtension "html" - compile $ pandocCompiler + compile $ pandocMathCompiler >>= loadAndApplyTemplate "templates/post.html" postCtxTags >>= saveSnapshot "feedContent" >>= loadAndApplyTemplate "templates/comments.html" postCtxTags @@ -86,7 +104,7 @@ main = do match "drafts/*" $ do route $ setExtension "html" - compile $ pandocCompiler + compile $ pandocMathCompiler >>= loadAndApplyTemplate "templates/post.html" postCtxTags >>= loadAndApplyTemplate "templates/default.html" postCtxTags >>= relativizeUrls diff --git a/templates/default.html b/templates/default.html index 653af89..043f29a 100644 --- a/templates/default.html +++ b/templates/default.html @@ -14,6 +14,11 @@ --> + + +