@@ -51,12 +51,13 @@ packPair :: (String, String) -> (B.ByteString, B.ByteString)
51packPair (a, b) = (B.pack a, B.pack b)
51packPair (a, b) = (B.pack a, B.pack b)
53-- | Get the URL for a certain page. This should always be defined. If
53-- | Get the URL for a certain page. This should always be defined. If
54−-- not, it will return trash.html.
54+-- not, it will error.
55getPageURL :: Page -> String
55getPageURL :: Page -> String
56−getPageURL (Page page) =
56+getPageURL (Page page) = B.unpack $ fromMaybe (error "No page url") $ M.lookup (B.pack "url") page
57− let result = M.lookup (B.pack "url") page
57+
58− in case result of (Just url) -> B.unpack url
58+-- | Get the original page path.
59− Nothing -> error "URL is not defined."
59+getPagePath :: Page -> String
60+getPagePath (Page page) = B.unpack $ fromMaybe (error "No page path") $ M.lookup (B.pack "path") page
61-- | Get the body for a certain page. When not defined, the body will be
62-- | Get the body for a certain page. When not defined, the body will be
@@ -128,7 +129,10 @@ readPage pagePath = do
128 let rendered = B.pack $ (renderFunction $ takeExtension path) body
129 let rendered = B.pack $ (renderFunction $ takeExtension path) body
129 seq rendered $ hClose handle
130 seq rendered $ hClose handle
130 let page = fromContext $ M.fromList $
131 let page = fromContext $ M.fromList $
132+ [ (B.pack "body", rendered)
133+ , packPair ("url", url)
134+ , packPair ("path", pagePath)
131− [(B.pack "body", rendered), packPair ("url", url)] ++ map packPair context
135+ ] ++ map packPair context
133 -- Cache if needed
137 -- Cache if needed
134 if getFromCache then return () else cachePage page
138 if getFromCache then return () else cachePage page
@@ -145,6 +149,6 @@ writePage page = do
146-- Make pages renderable.
150-- Make pages renderable.
147instance Renderable Page where
151instance Renderable Page where
148− getDependencies = (:[]) . flip addExtension ".html" . dropExtension . getPageURL
152+ getDependencies = (:[]) . getPagePath
149 getURL = getPageURL
153 getURL = getPageURL
150− toContext (Page mapping) = return mapping
154+ toContext (Page page) = return page