on master help sign in
Add setFieldA function
commit97ce6cbfa0c2935ec1958dc005b2d57d8a839206 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateSun 30 Jan 2011, 15:18 (16 years ago) parentc691251
1 file changed+15−2
src/Hakyll/Web/Page/Metadata.hs+15−2
src/Hakyll/Web/Page/Metadata.hs+15−2
@@ -3,6 +3,7 @@
33module Hakyll.Web.Page.Metadata
44 ( getField
55 , setField
6+ , setFieldA
67 , renderField
78 , changeField
89 , copyField
@@ -10,6 +11,9 @@ module Hakyll.Web.Page.Metadata
1011 , renderDateFieldWith
1112 ) where
1213
14+import Prelude hiding (id)
15+import Control.Category (id)
16+import Control.Arrow (Arrow, (>>>), (***), arr)
1317import Data.List (intercalate)
1418import Data.Maybe (fromMaybe)
1519import Data.Time.Clock (UTCTime)
@@ -37,6 +41,15 @@ setField :: String -- ^ Key
3741 -> Page a -- ^ Resulting page
3842setField k v (Page m b) = Page (M.insertWith (flip const) k v m) b
3943
44+-- | Arrow-based variant of 'setField'. Because of it's type, this function is
45+-- very usable together with the different 'require' functions.
46+--
47+setFieldA :: Arrow a
48+ => String -- ^ Key
49+ -> a x String -- ^ Value arrow
50+ -> a (Page String, x) (Page String) -- ^ Resulting arrow
51+setFieldA k v = id *** v >>> arr (uncurry $ flip $ setField k)
52+
4053-- | Do something with a metadata value, but keep the old value as well. If the
4154-- key given is not present in the metadata, nothing will happen. If the source
4255-- and destination keys are the same, the value will be changed (but you should
@@ -48,8 +61,8 @@ renderField :: String -- ^ Key of which the value should be copied
4861 -> Page a -- ^ Page on which this should be applied
4962 -> Page a -- ^ Resulting page
5063renderField src dst f page = case M.lookup src (pageMetadata page) of
51− Nothing -> page
52− (Just value) -> setField dst (f value) page
64+ Nothing -> page
65+ Just value -> setField dst (f value) page
5366
5467-- | Change a metadata value.
5568--