@@ -3,6 +3,7 @@
3module Hakyll.Web.Page.Metadata
3module Hakyll.Web.Page.Metadata
6 , renderField
7 , renderField
7 , changeField
8 , changeField
8 , copyField
9 , copyField
@@ -10,6 +11,9 @@ module Hakyll.Web.Page.Metadata
10 , renderDateFieldWith
11 , renderDateFieldWith
14+import Prelude hiding (id)
15+import Control.Category (id)
16+import Control.Arrow (Arrow, (>>>), (***), arr)
13import Data.List (intercalate)
17import Data.List (intercalate)
14import Data.Maybe (fromMaybe)
18import Data.Maybe (fromMaybe)
15import Data.Time.Clock (UTCTime)
19import Data.Time.Clock (UTCTime)
@@ -37,6 +41,15 @@ setField :: String -- ^ Key
37 -> Page a -- ^ Resulting page
41 -> Page a -- ^ Resulting page
38setField k v (Page m b) = Page (M.insertWith (flip const) k v m) b
42setField k v (Page m b) = Page (M.insertWith (flip const) k v m) b
44+-- | Arrow-based variant of 'setField'. Because of it's type, this function is
45+-- very usable together with the different 'require' functions.
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)
40-- | Do something with a metadata value, but keep the old value as well. If the
53-- | Do something with a metadata value, but keep the old value as well. If the
41-- key given is not present in the metadata, nothing will happen. If the source
54-- key given is not present in the metadata, nothing will happen. If the source
42-- and destination keys are the same, the value will be changed (but you should
55-- 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
48 -> Page a -- ^ Page on which this should be applied
61 -> Page a -- ^ Page on which this should be applied
49 -> Page a -- ^ Resulting page
62 -> Page a -- ^ Resulting page
50renderField src dst f page = case M.lookup src (pageMetadata page) of
63renderField src dst f page = case M.lookup src (pageMetadata page) of
51− Nothing -> page
64+ Nothing -> page
52− (Just value) -> setField dst (f value) page
65+ Just value -> setField dst (f value) page
54-- | Change a metadata value.
67-- | Change a metadata value.