Enabled MathJax rendering through Pandoc

This commit is contained in:
Chris Hodapp 2017-12-14 15:07:45 -05:00
parent e588dce485
commit cc3a24565f
3 changed files with 29 additions and 4 deletions

View File

@ -8,5 +8,7 @@ executable site
build-depends: base == 4.* build-depends: base == 4.*
, hakyll >= 4.6 , hakyll >= 4.6
, filepath , filepath
, containers
, pandoc
ghc-options: -threaded ghc-options: -threaded
default-language: Haskell2010 default-language: Haskell2010

26
site.hs
View File

@ -10,18 +10,36 @@ Portability : POSIX
import Data.Monoid (mappend) import Data.Monoid (mappend)
import Hakyll import Hakyll
import System.FilePath import System.FilePath
import Text.Pandoc.Options
import qualified GHC.IO.Encoding as E import qualified GHC.IO.Encoding as E
import qualified Data.Set as S
-- | Configuration for the RSS and ATOM feeds. -- | Configuration for the RSS and ATOM feeds.
feedConfiguration :: FeedConfiguration feedConfiguration :: FeedConfiguration
feedConfiguration = FeedConfiguration feedConfiguration = FeedConfiguration
{ feedTitle = "hodapple blog, FIXME!" { feedTitle = "hodapple blog"
, feedDescription = "FIXME!" , feedDescription = "FIXME!"
, feedAuthorName = "Chris Hodapp" , feedAuthorName = "Chris Hodapp"
, feedAuthorEmail = "Hodapp87@gmail.com" , feedAuthorEmail = "Hodapp87@gmail.com"
, feedRoot = "http://???" , 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 entry point for generating all code via Hakyll
main :: IO () main :: IO ()
main = do main = do
@ -57,7 +75,7 @@ main = do
match "pages/*" $ do match "pages/*" $ do
route $ setExtension "html" route $ setExtension "html"
compile $ pandocCompiler compile $ pandocMathCompiler
>>= loadAndApplyTemplate "templates/default.html" defaultContext >>= loadAndApplyTemplate "templates/default.html" defaultContext
>>= relativizeUrls >>= relativizeUrls
@ -72,7 +90,7 @@ main = do
match "posts/*" $ do match "posts/*" $ do
route $ setExtension "html" route $ setExtension "html"
compile $ pandocCompiler compile $ pandocMathCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtxTags >>= loadAndApplyTemplate "templates/post.html" postCtxTags
>>= saveSnapshot "feedContent" >>= saveSnapshot "feedContent"
>>= loadAndApplyTemplate "templates/comments.html" postCtxTags >>= loadAndApplyTemplate "templates/comments.html" postCtxTags
@ -86,7 +104,7 @@ main = do
match "drafts/*" $ do match "drafts/*" $ do
route $ setExtension "html" route $ setExtension "html"
compile $ pandocCompiler compile $ pandocMathCompiler
>>= loadAndApplyTemplate "templates/post.html" postCtxTags >>= loadAndApplyTemplate "templates/post.html" postCtxTags
>>= loadAndApplyTemplate "templates/default.html" postCtxTags >>= loadAndApplyTemplate "templates/default.html" postCtxTags
>>= relativizeUrls >>= relativizeUrls

View File

@ -14,6 +14,11 @@
--> -->
<link rel="stylesheet" type="text/css" href="/css/syntax.css"/> <link rel="stylesheet" type="text/css" href="/css/syntax.css"/>
<!-- From http://travis.athougies.net/posts/2013-08-13-using-math-on-your-hakyll-blog.html -->
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png"> <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png"> <link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png">