diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2009-12-25 23:06:01 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2009-12-25 23:06:01 +0100 |
commit | 637ab61284802c033372787d9af938282b8f69c5 (patch) | |
tree | 6dccb633543c4718dc63121d4420a6cb86d0e68c | |
parent | a53235285878d4199947b368ea703c30adf74710 (diff) | |
download | hakyll-637ab61284802c033372787d9af938282b8f69c5.tar.gz |
Added copyValueWith.
-rw-r--r-- | src/Text/Hakyll/Page.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs index ae1a2ea..0415755 100644 --- a/src/Text/Hakyll/Page.hs +++ b/src/Text/Hakyll/Page.hs @@ -1,6 +1,7 @@ module Text.Hakyll.Page ( Page, fromContext, + copyValueWith, getBody, readPage, writePage @@ -28,6 +29,17 @@ data Page = Page (M.Map B.ByteString B.ByteString) fromContext :: (M.Map B.ByteString B.ByteString) -> Page fromContext = Page +-- | Do something with a value of the page. +copyValueWith :: String -- ^ Key of which the value should be copied. + -> String -- ^ Key the value should be copied to. + -> (B.ByteString -> B.ByteString) -- ^ Function to apply on the value. + -> Page -- ^ Page on which to apply this modification. + -> Page -- ^ Result. +copyValueWith src dst f p@(Page page) = case M.lookup (B.pack src) page of + Nothing -> p + (Just value) -> Page $ M.insert (B.pack dst) (f value) page + + -- | Auxiliary function to pack a pair. packPair :: (String, String) -> (B.ByteString, B.ByteString) packPair (a, b) = (B.pack a, B.pack b) |