on master help sign in
Add mapContext again
commitab0aebb3c3b0ceec565af673b0de6bf141585b83 authorJasper Van der Jeugt <m@jaspervdj.be> dateMon 5 Aug 2013, 12:25 (13 years ago) parente12c4e3
2 files changed+12−2
hakyll.cabal+1−1 src/Hakyll/Web/Template/Context.hs+11−1
hakyll.cabal+1−1
@@ -1,5 +1,5 @@
11Name: hakyll
2−Version: 4.3.1.0
2+Version: 4.3.2.0
33
44Synopsis: A static website compiler library
55Description:
src/Hakyll/Web/Template/Context.hs+11−1
@@ -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--------------------------------------------------------------------------------