summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-25 23:06:01 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-25 23:06:01 +0100
commit637ab61284802c033372787d9af938282b8f69c5 (patch)
tree6dccb633543c4718dc63121d4420a6cb86d0e68c
parenta53235285878d4199947b368ea703c30adf74710 (diff)
downloadhakyll-637ab61284802c033372787d9af938282b8f69c5.tar.gz
Added copyValueWith.
-rw-r--r--src/Text/Hakyll/Page.hs12
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)