on master help sign in
Added general renderAndConcat function.
35e6572Jasper Van der Jeugt
hakyll.cabal+1
@@ -7,6 +7,7 @@ Description:
7 creating blogs.
7 creating blogs.
8Author: Jasper Van der Jeugt
8Author: Jasper Van der Jeugt
9Maintainer: jaspervdj@gmail.com
9Maintainer: jaspervdj@gmail.com
10+Homepage: http://github.com/jaspervdj/Hakyll
10License: BSD3
11License: BSD3
11License-File: LICENSE
12License-File: LICENSE
12Category: Text
13Category: Text
src/Text/Hakyll/Page.hs+5−5
@@ -51,11 +51,11 @@ writerOptions = defaultWriterOptions
51renderFunction :: String -> (String -> String)
51renderFunction :: String -> (String -> String)
52renderFunction ".html" = id
52renderFunction ".html" = id
53renderFunction ext = writeHtmlString writerOptions .
53renderFunction ext = writeHtmlString writerOptions .
54− renderFunction' ext defaultParserState
54+ readFunction ext defaultParserState
55− where renderFunction' ".markdown" = readMarkdown
55+ where readFunction ".markdown" = readMarkdown
56− renderFunction' ".md" = readMarkdown
56+ readFunction ".md" = readMarkdown
57− renderFunction' ".tex" = readLaTeX
57+ readFunction ".tex" = readLaTeX
58− renderFunction' _ = readMarkdown
58+ readFunction _ = readMarkdown
59
59
60readMetaData :: Handle -> IO [(String, String)]
60readMetaData :: Handle -> IO [(String, String)]
61readMetaData handle = do
61readMetaData handle = do
src/Text/Hakyll/Render.hs+11−1
@@ -1,6 +1,7 @@
1module Text.Hakyll.Render
1module Text.Hakyll.Render
2 ( renderPage,
2 ( renderPage,
3 renderAndWrite,
3 renderAndWrite,
4+ renderAndConcat,
4 static,
5 static,
5 staticDirectory
6 staticDirectory
6 ) where
7 ) where
@@ -26,7 +27,7 @@ renderPage templatePath page = do
26 templateString <- liftM B.pack $ hGetContents handle
27 templateString <- liftM B.pack $ hGetContents handle
27 seq templateString $ hClose handle
28 seq templateString $ hClose handle
28 let body = substitute templateString (createContext page)
29 let body = substitute templateString (createContext page)
29− return $ addContext "body" (B.unpack body) page
30+ return $ M.insert "body" body page
30
31
31renderAndWrite :: FilePath -> Page -> IO ()
32renderAndWrite :: FilePath -> Page -> IO ()
32renderAndWrite templatePath page = do
33renderAndWrite templatePath page = do
@@ -35,6 +36,15 @@ renderAndWrite templatePath page = do
35 makeDirectories destination
36 makeDirectories destination
36 B.writeFile destination (getBody rendered)
37 B.writeFile destination (getBody rendered)
37
38
39+renderAndConcat :: FilePath -> [FilePath] -> IO B.ByteString
40+renderAndConcat templatePath paths = foldM concatRender' B.empty paths
41+ where concatRender' :: B.ByteString -> FilePath -> IO B.ByteString
42+ concatRender' chunk path = do
43+ page <- readPage path
44+ rendered <- renderPage templatePath page
45+ let body = getBody rendered
46+ return $ B.append chunk $ body
47+
38static :: FilePath -> IO ()
48static :: FilePath -> IO ()
39static source = do
49static source = do
40 makeDirectories destination
50 makeDirectories destination