@@ -1,10 +1,8 @@
1module Text.Hakyll.Page
1module Text.Hakyll.Page
3 fromContext,
3 fromContext,
10import qualified Data.Map as M
8import qualified Data.Map as M
@@ -28,10 +26,6 @@ data Page = Page (M.Map B.ByteString B.ByteString)
28fromContext :: (M.Map B.ByteString B.ByteString) -> Page
26fromContext :: (M.Map B.ByteString B.ByteString) -> Page
29fromContext = Page
27fromContext = Page
31−-- | Add a key-value mapping to the Page.
32−addContext :: String -> String -> Page -> Page
33−addContext key value (Page page) = Page $ M.insert (B.pack key) (B.pack value) page
35-- | Auxiliary function to pack a pair.
29-- | Auxiliary function to pack a pair.
36packPair :: (String, String) -> (B.ByteString, B.ByteString)
30packPair :: (String, String) -> (B.ByteString, B.ByteString)
37packPair (a, b) = (B.pack a, B.pack b)
31packPair (a, b) = (B.pack a, B.pack b)
@@ -113,7 +107,8 @@ readPage pagePath = do
113 -- Render file
107 -- Render file
114 let rendered = B.pack $ (renderFunction $ takeExtension path) body
108 let rendered = B.pack $ (renderFunction $ takeExtension path) body
115 seq rendered $ hClose handle
109 seq rendered $ hClose handle
110+ let page = fromContext $ M.fromList $
116− let page = addContext "url" url $ Page $ M.fromList $ (B.pack "body", rendered) : map packPair context
111+ [(B.pack "body", rendered), packPair ("url", url)] ++ map packPair context
118 -- Cache if needed
113 -- Cache if needed
119 if getFromCache then return () else cachePage page
114 if getFromCache then return () else cachePage page
@@ -121,10 +116,6 @@ readPage pagePath = do
121 where url = toURL pagePath
116 where url = toURL pagePath
122 cacheFile = toCache url
117 cacheFile = toCache url
124−-- | Create a key-value mapping page from an association list.
125−pageFromList :: [(String, String)] -> Page
126−pageFromList = Page . M.fromList . map packPair
128-- Make pages renderable.
119-- Make pages renderable.
129instance Renderable Page where
120instance Renderable Page where
130 getDependencies = (:[]) . flip addExtension ".html" . dropExtension . getPageURL
121 getDependencies = (:[]) . flip addExtension ".html" . dropExtension . getPageURL