summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)