Better module definitions.
This commit is contained in:
parent
36e4bf881b
commit
f716440837
4 changed files with 30 additions and 7 deletions
|
@ -12,8 +12,10 @@ Cabal-Version: >= 1.2
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
|
|
||||||
library
|
library
|
||||||
|
ghc-options: -Wall
|
||||||
hs-source-dirs: src/
|
hs-source-dirs: src/
|
||||||
build-depends: base > 4, template, filepath, directory, containers, bytestring,
|
build-depends: base >= 4 && < 5, template, filepath, directory, containers, bytestring,
|
||||||
pandoc >= 1
|
pandoc >= 1
|
||||||
exposed-modules: Text.Hakyll.Render
|
exposed-modules: Text.Hakyll.Render
|
||||||
Text.Hakyll.Page
|
Text.Hakyll.Page
|
||||||
|
Text.Hakyll.Util
|
||||||
|
|
|
@ -1,4 +1,12 @@
|
||||||
module Text.Hakyll.Page where
|
module Text.Hakyll.Page
|
||||||
|
( Page,
|
||||||
|
addContext,
|
||||||
|
getURL,
|
||||||
|
getBody,
|
||||||
|
readPage,
|
||||||
|
pageFromList,
|
||||||
|
concatPages
|
||||||
|
) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import qualified Data.List as L
|
import qualified Data.List as L
|
||||||
|
@ -18,7 +26,7 @@ getBody :: Page -> String
|
||||||
getBody context = fromMaybe "" $ M.lookup "body" context
|
getBody context = fromMaybe "" $ M.lookup "body" context
|
||||||
|
|
||||||
readConfig :: [String] -> Page
|
readConfig :: [String] -> Page
|
||||||
readConfig lines = M.fromList $ map (trim . break (== ':')) lines
|
readConfig = M.fromList . map (trim . break (== ':'))
|
||||||
where trim (key, value) = (key, dropWhile (`elem` ": ") value)
|
where trim (key, value) = (key, dropWhile (`elem` ": ") value)
|
||||||
|
|
||||||
extractContext :: String -> Page
|
extractContext :: String -> Page
|
||||||
|
@ -45,3 +53,8 @@ readPage path = do
|
||||||
url = addExtension (dropExtension path) ".html"
|
url = addExtension (dropExtension path) ".html"
|
||||||
return $ addContext "url" url $ addContext "body" body $ context
|
return $ addContext "url" url $ addContext "body" body $ context
|
||||||
|
|
||||||
|
pageFromList :: [(String, String)] -> Page
|
||||||
|
pageFromList = M.fromList
|
||||||
|
|
||||||
|
concatPages :: [Page] -> String
|
||||||
|
concatPages = concat . map getBody
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
module Text.Hakyll.Render where
|
module Text.Hakyll.Render
|
||||||
|
( renderPage,
|
||||||
|
renderAndWrite,
|
||||||
|
static,
|
||||||
|
staticDirectory
|
||||||
|
) where
|
||||||
|
|
||||||
import Text.Template
|
import Text.Template
|
||||||
import qualified Data.ByteString.Lazy.Char8 as B
|
import qualified Data.ByteString.Lazy.Char8 as B
|
||||||
|
@ -20,8 +25,8 @@ createContext = M.fromList . map packPair . M.toList
|
||||||
|
|
||||||
renderPage :: FilePath -> Page -> IO Page
|
renderPage :: FilePath -> Page -> IO Page
|
||||||
renderPage templatePath page = do
|
renderPage templatePath page = do
|
||||||
template <- B.readFile templatePath
|
templateString <- B.readFile templatePath
|
||||||
let body = substitute template (createContext page)
|
let body = substitute templateString (createContext page)
|
||||||
return $ addContext "body" (B.unpack body) page
|
return $ addContext "body" (B.unpack body) page
|
||||||
|
|
||||||
renderAndWrite :: FilePath -> Page -> IO ()
|
renderAndWrite :: FilePath -> Page -> IO ()
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
module Text.Hakyll.Util where
|
module Text.Hakyll.Util
|
||||||
|
( touchDirectories,
|
||||||
|
getRecursiveContents
|
||||||
|
) where
|
||||||
|
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
|
Loading…
Reference in a new issue