@@ -6,6 +6,7 @@ module Hakyll.Web.Template.Context
66 , field
77 , constField
88 , listField
9+ , mapContext
910
1011 , defaultContext
1112 , bodyField
@@ -85,6 +86,15 @@ listField :: String -> Context a -> Compiler [Item a] -> Context b
8586listField key c xs = field' key $ \_ -> fmap (ListField c) xs
8687
8788
89+--------------------------------------------------------------------------------
90+mapContext :: (String -> String) -> Context a -> Context a
91+mapContext f (Context c) = Context $ \k i -> do
92+ fld <- c k i
93+ return $ case fld of
94+ StringField str -> StringField (f str)
95+ ListField ctx is -> ListField ctx is
96+
97+
8898--------------------------------------------------------------------------------
8999defaultContext :: Context String
90100defaultContext =
@@ -130,7 +140,7 @@ pathField key = field key $ return . toFilePath . itemIdentifier
130140--------------------------------------------------------------------------------
131141-- | This title field takes the basename of the underlying file by default
132142titleField :: String -> Context a
133−titleField key = field key $ return . takeBaseName . toFilePath . itemIdentifier
143+titleField = mapContext takeBaseName . pathField
134144
135145
136146--------------------------------------------------------------------------------