diff options
author | JJ | 2024-07-22 04:42:42 +0000 |
---|---|---|
committer | JJ | 2024-07-22 20:21:58 +0000 |
commit | 3c11f6cca5b73e188289ada66e7924b4b33e4f59 (patch) | |
tree | 2c410c7856d30985dfabf4319dcc6385a6872d1a /site.hs | |
parent | 2a99a0556e17771181eb31b1c9f6fb6ed335158f (diff) |
replace jekyll with hakyll
Diffstat (limited to 'site.hs')
-rw-r--r-- | site.hs | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -0,0 +1,62 @@ +{-# 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 = + let defaultExtensions = writerExtensions defaultHakyllWriterOptions + addedExtensions = extensionsFromList [Ext_lists_without_preceding_blankline] + removedExtensions = extensionsFromList [Ext_blank_before_header, Ext_blank_before_blockquote] + writerOptions = defaultHakyllWriterOptions { + writerExtensions = disableExtensions (defaultExtensions <> pandocExtensions <> addedExtensions) removedExtensions, + writerHTMLMathMethod = MathML, + writerHighlightStyle = Just zenburn + } + in pandocCompilerWith defaultHakyllReaderOptions writerOptions + +-- 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" .||. "**.markdown") $ do + route $ setExtension "html" + compile $ pandocCompiler + >>= loadLayoutTemplate defaultContext + >>= relativizeUrls + + -- Additionally copy non-HTML files verbatium + match ("**.md" .||. "**.markdown") $ version "raw" $ do + route idRoute + compile pandocCompiler + + -- Copy all additional files verbatium + match "**" $ do + route idRoute + compile copyFileCompiler |