summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2013-08-05 12:25:05 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2013-08-05 12:25:55 +0200
commitab0aebb3c3b0ceec565af673b0de6bf141585b83 (patch)
treeb389560ef7d495ab12c03ef11ff135894a25e022 /src/Hakyll
parente12c4e36ff5452d0097e396af4a8747d144293d1 (diff)
downloadhakyll-ab0aebb3c3b0ceec565af673b0de6bf141585b83.tar.gz
Add mapContext again
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Web/Template/Context.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/Hakyll/Web/Template/Context.hs b/src/Hakyll/Web/Template/Context.hs
index ecf769d..fe63c38 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
+ , mapContext
, defaultContext
, bodyField
@@ -86,6 +87,15 @@ listField key c xs = field' key $ \_ -> fmap (ListField c) xs
--------------------------------------------------------------------------------
+mapContext :: (String -> String) -> Context a -> Context a
+mapContext f (Context c) = Context $ \k i -> do
+ fld <- c k i
+ return $ case fld of
+ StringField str -> StringField (f str)
+ ListField ctx is -> ListField ctx is
+
+
+--------------------------------------------------------------------------------
defaultContext :: Context String
defaultContext =
bodyField "body" `mappend`
@@ -130,7 +140,7 @@ pathField key = field key $ return . toFilePath . itemIdentifier
--------------------------------------------------------------------------------
-- | This title field takes the basename of the underlying file by default
titleField :: String -> Context a
-titleField key = field key $ return . takeBaseName . toFilePath . itemIdentifier
+titleField = mapContext takeBaseName . pathField
--------------------------------------------------------------------------------