diff options
-rw-r--r-- | hakyll.cabal | 2 | ||||
-rw-r--r-- | src/Hakyll/Web/Template/Context.hs | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/hakyll.cabal b/hakyll.cabal index ced01c6..e552bf3 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -1,5 +1,5 @@ Name: hakyll -Version: 4.3.1.0 +Version: 4.3.2.0 Synopsis: A static website compiler library Description: 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 -------------------------------------------------------------------------------- |