diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2009-12-03 11:08:55 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2009-12-03 11:08:55 +0100 |
commit | b7e01c4ca47dc01e7f4f695214d57a3a9f9e1deb (patch) | |
tree | 234b05b5567e0579f0d066eef60f03ba41c5cbb2 | |
parent | 1db2e00bbb813795cf858f69c21fa6c6837091a0 (diff) | |
download | hakyll-b7e01c4ca47dc01e7f4f695214d57a3a9f9e1deb.tar.gz |
Documented functions in Text.Hakyll.Page.
-rw-r--r-- | src/Text/Hakyll/Page.hs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs index 7e9a76e..5b3586d 100644 --- a/src/Text/Hakyll/Page.hs +++ b/src/Text/Hakyll/Page.hs @@ -5,7 +5,8 @@ module Text.Hakyll.Page getBody, readPage, pageFromList, - concatPages + concatPages, + concatPagesWith ) where import qualified Data.Map as M @@ -14,14 +15,21 @@ import System.FilePath import Data.Maybe import Text.Pandoc +-- | A Page is basically key-value mapping. Certain keys have special +-- meanings, like for example url, body and title. type Page = M.Map String String +-- | Add a key-value mapping to the Page. addContext :: String -> String -> Page -> Page addContext = M.insert +-- | Get the URL for a certain page. This should always be defined. If +-- not, it will return trash.html. getURL :: Page -> String -getURL context = fromMaybe "404.html" $ M.lookup "url" context +getURL context = fromMaybe "trash.html" $ M.lookup "url" context +-- | Get the body for a certain page. When not defined, the body will be +-- empty. getBody :: Page -> String getBody context = fromMaybe "" $ M.lookup "body" context @@ -44,6 +52,9 @@ markdownToHTML :: String -> String markdownToHTML = writeHtmlString writerOptions . readMarkdown defaultParserState +-- | Read a page from a file. Metadata is supported, and if the filename +-- has a .markdown extension, it will be rendered using pandoc. Note that +-- pages are not templates, so they should not contain $identifiers. readPage :: FilePath -> IO Page readPage path = do content <- readFile path @@ -53,8 +64,16 @@ readPage path = do url = addExtension (dropExtension path) ".html" return $ addContext "url" url $ addContext "body" body $ context +-- | Create a key-value mapping page from an association list. pageFromList :: [(String, String)] -> Page pageFromList = M.fromList +-- | Concat the bodies of pages, and return the result. concatPages :: [Page] -> String -concatPages = concat . map getBody +concatPages = concatPagesWith "body" + +-- | Concat certain values of pages, and return the result. +concatPagesWith :: String -- ^ Key of which to concat the values. + -> [Page] -- ^ Pages to get the values from. + -> String -- ^ The concatenation. +concatPagesWith key = concat . map (fromMaybe "" . M.lookup key) |