{-# LANGUAGE OverloadedStrings #-} import Hakyll hiding (pandocCompiler) import Text.Pandoc.Options import Text.Pandoc.Highlighting -- Pass custom options to the Pandoc compiler pandocCompiler :: Compiler (Item String) pandocCompiler = pandocCompilerWith readerOptions writerOptions where writerOptions = defaultHakyllWriterOptions { writerExtensions = writerExtensions defaultHakyllWriterOptions <> pandocExtensions, writerHTMLMathMethod = MathML } readerOptions = defaultHakyllReaderOptions { readerExtensions = readerExtensions defaultHakyllReaderOptions <> pandocExtensions <> extensionsFromList [Ext_lists_without_preceding_blankline] } -- Loads the template specified in a post's metadata, if it exists loadLayoutTemplate :: Context String -> Item String -> Compiler (Item String) loadLayoutTemplate context item = do field <- getMetadataField (itemIdentifier item) "layout" case field of Just path -> let templatePath = "_templates/" ++ path ++ ".html" in loadAndApplyTemplate (fromFilePath templatePath) context item _ -> return item main :: IO () main = hakyll $ do -- Compile templates for future use match "_templates/*" $ compile templateBodyCompiler -- Detect whether HTML files are standalone or in need of a template match ("**.html" .||. "**.htm") $ do route idRoute compile $ do identifier <- getUnderlying field <- getMetadataField identifier "layout" case field of Just _ -> pandocCompiler Nothing -> getResourceBody >>= loadLayoutTemplate defaultContext >>= relativizeUrls -- Match all other renderable files and apply their template, if it exists match ("**.md" .||. "**.rst" .||. "**.org" .||. "**.adoc") $ do route $ setExtension "html" compile $ pandocCompiler >>= loadLayoutTemplate defaultContext >>= relativizeUrls -- Additionally copy non-HTML files raw, without front matter match ("**.md" .||. "**.rst" .||. "**.org" .||. "**.adoc") $ version "raw" $ do route idRoute compile getResourceBody -- Copy all additional files verbatium match "**" $ do route idRoute compile copyFileCompiler