aboutsummaryrefslogtreecommitdiff
path: root/sticks.hs
diff options
context:
space:
mode:
authorJJ2024-07-23 00:33:19 +0000
committerJJ2024-07-23 01:10:39 +0000
commitfaa912ea2bcb95b7d7e8822a2647229d294dc368 (patch)
tree0f944ca8e261710bc3880360900856bfa6d39006 /sticks.hs
Initial commitHEADmain
Diffstat (limited to 'sticks.hs')
-rw-r--r--sticks.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/sticks.hs b/sticks.hs
new file mode 100644
index 0000000..36607d8
--- /dev/null
+++ b/sticks.hs
@@ -0,0 +1,47 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+import Hakyll
+
+-- Applies the template specified in a post's metadata, if it exists
+applyMetadataTemplate :: Context String -> Item String -> Compiler (Item String)
+applyMetadataTemplate context item = do
+ field <- getMetadataField (itemIdentifier item) "template"
+ 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
+ >>= applyMetadataTemplate 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
+ >>= applyMetadataTemplate defaultContext
+ >>= relativizeUrls
+
+ -- Additionally copy non-HTML files verbatium
+ match ("**.md" .||. "**.rst" .||. "**.org" .||. "**.adoc") $ version "raw" $ do
+ route idRoute
+ compile pandocCompiler
+
+ -- Copy all additional files verbatium
+ match "**" $ do
+ route idRoute
+ compile copyFileCompiler