@@ -51,12 +51,13 @@ packPair :: (String, String) -> (B.ByteString, B.ByteString)
5151packPair (a, b) = (B.pack a, B.pack b)
5252
5353-- | 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.
5555getPageURL :: Page -> String
56−getPageURL (Page page) =
57− let result = M.lookup (B.pack "url") page
58− in case result of (Just url) -> B.unpack url
59− Nothing -> error "URL is not defined."
56+getPageURL (Page page) = B.unpack $ fromMaybe (error "No page url") $ M.lookup (B.pack "url") page
57+
58+-- | Get the original page path.
59+getPagePath :: Page -> String
60+getPagePath (Page page) = B.unpack $ fromMaybe (error "No page path") $ M.lookup (B.pack "path") page
6061
6162-- | Get the body for a certain page. When not defined, the body will be
6263-- empty.
@@ -128,7 +129,10 @@ readPage pagePath = do
128129 let rendered = B.pack $ (renderFunction $ takeExtension path) body
129130 seq rendered $ hClose handle
130131 let page = fromContext $ M.fromList $
131− [(B.pack "body", rendered), packPair ("url", url)] ++ map packPair context
132+ [ (B.pack "body", rendered)
133+ , packPair ("url", url)
134+ , packPair ("path", pagePath)
135+ ] ++ map packPair context
132136
133137 -- Cache if needed
134138 if getFromCache then return () else cachePage page
@@ -145,6 +149,6 @@ writePage page = do
145149
146150-- Make pages renderable.
147151instance Renderable Page where
148− getDependencies = (:[]) . flip addExtension ".html" . dropExtension . getPageURL
152+ getDependencies = (:[]) . getPagePath
149153 getURL = getPageURL
150− toContext (Page mapping) = return mapping
154+ toContext (Page page) = return page