diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2009-12-26 09:58:15 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2009-12-26 09:58:15 +0100 |
commit | c790065b464234454773bbe98ab85111634311ae (patch) | |
tree | ae8a1ba1be298d536cdebfc656cddb9565c7318f /src/Text | |
parent | 58ad6a9d38bc74152128f52a9636d6e5e20c1b93 (diff) | |
download | hakyll-c790065b464234454773bbe98ab85111634311ae.tar.gz |
Added original page path to Page records.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Hakyll/Page.hs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs index cecb686..89e1bef 100644 --- a/src/Text/Hakyll/Page.hs +++ b/src/Text/Hakyll/Page.hs @@ -51,12 +51,13 @@ packPair :: (String, String) -> (B.ByteString, B.ByteString) packPair (a, b) = (B.pack a, B.pack b) -- | Get the URL for a certain page. This should always be defined. If --- not, it will return trash.html. +-- not, it will error. getPageURL :: Page -> String -getPageURL (Page page) = - let result = M.lookup (B.pack "url") page - in case result of (Just url) -> B.unpack url - Nothing -> error "URL is not defined." +getPageURL (Page page) = B.unpack $ fromMaybe (error "No page url") $ M.lookup (B.pack "url") page + +-- | Get the original page path. +getPagePath :: Page -> String +getPagePath (Page page) = B.unpack $ fromMaybe (error "No page path") $ M.lookup (B.pack "path") page -- | Get the body for a certain page. When not defined, the body will be -- empty. @@ -128,7 +129,10 @@ readPage pagePath = do let rendered = B.pack $ (renderFunction $ takeExtension path) body seq rendered $ hClose handle let page = fromContext $ M.fromList $ - [(B.pack "body", rendered), packPair ("url", url)] ++ map packPair context + [ (B.pack "body", rendered) + , packPair ("url", url) + , packPair ("path", pagePath) + ] ++ map packPair context -- Cache if needed if getFromCache then return () else cachePage page @@ -145,6 +149,6 @@ writePage page = do -- Make pages renderable. instance Renderable Page where - getDependencies = (:[]) . flip addExtension ".html" . dropExtension . getPageURL + getDependencies = (:[]) . getPagePath getURL = getPageURL - toContext (Page mapping) = return mapping + toContext (Page page) = return page |