From b7e01c4ca47dc01e7f4f695214d57a3a9f9e1deb Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Thu, 3 Dec 2009 11:08:55 +0100 Subject: Documented functions in Text.Hakyll.Page. --- src/Text/Hakyll/Page.hs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/Text') 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) -- cgit v1.2.3