summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Web')
-rw-r--r--src/Hakyll/Web/Template/Context.hs10
-rw-r--r--src/Hakyll/Web/Template/Read.hs2
2 files changed, 11 insertions, 1 deletions
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs
index fe63c38..428e105 100644
--- a/src/Hakyll/Web/Template/Context.hs
+++ b/src/Hakyll/Web/Template/Context.hs
@@ -6,6 +6,7 @@ module Hakyll.Web.Template.Context
, field
, constField
, listField
+ , functionField
, mapContext
, defaultContext
@@ -87,6 +88,15 @@ listField key c xs = field' key $ \_ -> fmap (ListField c) xs
--------------------------------------------------------------------------------
+functionField :: String -> ([String] -> Item a -> Compiler String) -> Context a
+functionField name value = Context $ \k i -> case words k of
+ [] -> empty
+ (n : args)
+ | n == name -> StringField <$> value args i
+ | otherwise -> empty
+
+
+--------------------------------------------------------------------------------
mapContext :: (String -> String) -> Context a -> Context a
mapContext f (Context c) = Context $ \k i -> do
fld <- c k i
diff --git a/src/Hakyll/Web/Template/Read.hs b/src/Hakyll/Web/Template/Read.hs
index bb5c8c2..2421b2d 100644
--- a/src/Hakyll/Web/Template/Read.hs
+++ b/src/Hakyll/Web/Template/Read.hs
@@ -21,7 +21,7 @@ import Hakyll.Web.Template.Internal
readTemplate :: String -> Template
readTemplate input = case parse template "" input of
Left err -> error $ "Cannot parse template: " ++ show err
- Right t -> t
+ Right t -> t
--------------------------------------------------------------------------------