From ab0aebb3c3b0ceec565af673b0de6bf141585b83 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 5 Aug 2013 12:25:05 +0200 Subject: Add mapContext again --- src/Hakyll/Web/Template/Context.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/Hakyll/Web') 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 @@ -85,6 +86,15 @@ listField :: String -> Context a -> Compiler [Item a] -> Context b 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 = @@ -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 -------------------------------------------------------------------------------- -- cgit v1.2.3