on master help sign in
Better module definitions.
f716440Jasper Van der Jeugt
hakyll.cabal+3−1
@@ -12,8 +12,10 @@ Cabal-Version: >= 1.2
12build-type: Simple
12build-type: Simple
13
13
14library
14library
15+ ghc-options: -Wall
15 hs-source-dirs: src/
16 hs-source-dirs: src/
16− build-depends: base > 4, template, filepath, directory, containers, bytestring,
17+ build-depends: base >= 4 && < 5, template, filepath, directory, containers, bytestring,
17 pandoc >= 1
18 pandoc >= 1
18 exposed-modules: Text.Hakyll.Render
19 exposed-modules: Text.Hakyll.Render
19 Text.Hakyll.Page
20 Text.Hakyll.Page
21+ Text.Hakyll.Util
src/Text/Hakyll/Page.hs+15−2
@@ -1,4 +1,12 @@
1−module Text.Hakyll.Page where
1+module Text.Hakyll.Page
2+ ( Page,
3+ addContext,
4+ getURL,
5+ getBody,
6+ readPage,
7+ pageFromList,
8+ concatPages
9+ ) where
2
10
3import qualified Data.Map as M
11import qualified Data.Map as M
4import qualified Data.List as L
12import qualified Data.List as L
@@ -18,7 +26,7 @@ getBody :: Page -> String
18getBody context = fromMaybe "" $ M.lookup "body" context
26getBody context = fromMaybe "" $ M.lookup "body" context
19
27
20readConfig :: [String] -> Page
28readConfig :: [String] -> Page
21−readConfig lines = M.fromList $ map (trim . break (== ':')) lines
29+readConfig = M.fromList . map (trim . break (== ':'))
22 where trim (key, value) = (key, dropWhile (`elem` ": ") value)
30 where trim (key, value) = (key, dropWhile (`elem` ": ") value)
23
31
24extractContext :: String -> Page
32extractContext :: String -> Page
@@ -45,3 +53,8 @@ readPage path = do
45 url = addExtension (dropExtension path) ".html"
53 url = addExtension (dropExtension path) ".html"
46 return $ addContext "url" url $ addContext "body" body $ context
54 return $ addContext "url" url $ addContext "body" body $ context
47
55
56+pageFromList :: [(String, String)] -> Page
57+pageFromList = M.fromList
58+
59+concatPages :: [Page] -> String
60+concatPages = concat . map getBody
src/Text/Hakyll/Render.hs+8−3
@@ -1,4 +1,9 @@
1−module Text.Hakyll.Render where
1+module Text.Hakyll.Render
2+ ( renderPage,
3+ renderAndWrite,
4+ static,
5+ staticDirectory
6+ ) where
2
7
3import Text.Template
8import Text.Template
4import qualified Data.ByteString.Lazy.Char8 as B
9import qualified Data.ByteString.Lazy.Char8 as B
@@ -20,8 +25,8 @@ createContext = M.fromList . map packPair . M.toList
20
25
21renderPage :: FilePath -> Page -> IO Page
26renderPage :: FilePath -> Page -> IO Page
22renderPage templatePath page = do
27renderPage templatePath page = do
23− template <- B.readFile templatePath
28+ templateString <- B.readFile templatePath
24− let body = substitute template (createContext page)
29+ let body = substitute templateString (createContext page)
25 return $ addContext "body" (B.unpack body) page
30 return $ addContext "body" (B.unpack body) page
26
31
27renderAndWrite :: FilePath -> Page -> IO ()
32renderAndWrite :: FilePath -> Page -> IO ()
src/Text/Hakyll/Util.hs+4−1
@@ -1,4 +1,7 @@
1−module Text.Hakyll.Util where
1+module Text.Hakyll.Util
2+ ( touchDirectories,
3+ getRecursiveContents
4+ ) where
2
5
3import System.Directory
6import System.Directory
4import System.FilePath
7import System.FilePath