diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-03-01 22:22:11 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2011-03-01 22:26:02 +0100 |
commit | c14d8871b8b2df51735948b50f53677a06924a5b (patch) | |
tree | 4694d6f4ecab964fe9ab5ee5c28edccd14e54516 /src/Hakyll/Web/Page/Metadata.hs | |
parent | 1a7d746ad5be0b9469d664f21ca1aa79ce2154bb (diff) | |
download | hakyll-c14d8871b8b2df51735948b50f53677a06924a5b.tar.gz |
Add trySetField, fix bug in renderField
Diffstat (limited to 'src/Hakyll/Web/Page/Metadata.hs')
-rw-r--r-- | src/Hakyll/Web/Page/Metadata.hs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/Hakyll/Web/Page/Metadata.hs b/src/Hakyll/Web/Page/Metadata.hs index 72742e6..b0545f3 100644 --- a/src/Hakyll/Web/Page/Metadata.hs +++ b/src/Hakyll/Web/Page/Metadata.hs @@ -4,6 +4,7 @@ module Hakyll.Web.Page.Metadata ( getField , getFieldMaybe , setField + , trySetField , setFieldA , renderField , changeField @@ -41,13 +42,21 @@ getFieldMaybe :: String -- ^ Key -> Maybe String -- ^ Value, if found getFieldMaybe key = M.lookup key . pageMetadata --- | Add a metadata field. If the field already exists, it is not overwritten. +-- | Version of 'trySetField' which overrides any previous value -- setField :: String -- ^ Key -> String -- ^ Value -> Page a -- ^ Page to add it to -> Page a -- ^ Resulting page -setField k v (Page m b) = Page (M.insertWith (flip const) k v m) b +setField k v (Page m b) = Page (M.insert k v m) b + +-- | Add a metadata field. If the field already exists, it is not overwritten. +-- +trySetField :: String -- ^ Key + -> String -- ^ Value + -> Page a -- ^ Page to add it to + -> Page a -- ^ Resulting page +trySetField k v (Page m b) = Page (M.insertWith (flip const) k v m) b -- | Arrow-based variant of 'setField'. Because of it's type, this function is -- very usable together with the different 'require' functions. |