on master help sign in
Merged Text.Hakyll.Internal.Render into Text.Hakyll.Render.
35e8246Jasper Van der Jeugt
hakyll.cabal−1
@@ -58,6 +58,5 @@ library
58 Text.Hakyll.Internal.CompressCss
58 Text.Hakyll.Internal.CompressCss
59 Text.Hakyll.Internal.FileType
59 Text.Hakyll.Internal.FileType
60 Text.Hakyll.Internal.Page
60 Text.Hakyll.Internal.Page
61− Text.Hakyll.Internal.Render
62 Text.Hakyll.Internal.Template
61 Text.Hakyll.Internal.Template
63 other-modules: Paths_hakyll
62 other-modules: Paths_hakyll
src/Network/Hakyll/SimpleServer.hs+10−10
@@ -143,16 +143,16 @@ getMIMEHeader fileName =
143 Nothing -> []
143 Nothing -> []
144 where
144 where
145 result = lookup (takeExtension fileName) [ (".css", "text/css")
145 result = lookup (takeExtension fileName) [ (".css", "text/css")
146− , (".gif", "image/gif")
146+ , (".gif", "image/gif")
147− , (".htm", "text/html")
147+ , (".htm", "text/html")
148− , (".html", "text/html")
148+ , (".html", "text/html")
149− , (".jpeg", "image/jpeg")
149+ , (".jpeg", "image/jpeg")
150− , (".jpg", "image/jpeg")
150+ , (".jpg", "image/jpeg")
151− , (".js", "text/javascript")
151+ , (".js", "text/javascript")
152− , (".png", "image/png")
152+ , (".png", "image/png")
153− , (".txt", "text/plain")
153+ , (".txt", "text/plain")
154− , (".xml", "text/xml")
154+ , (".xml", "text/xml")
155− ]
155+ ]
156
156
157-- | Respond to an incoming request.
157-- | Respond to an incoming request.
158respond :: Handle -> Server ()
158respond :: Handle -> Server ()
src/Text/Hakyll/Feed.hs+1−1
@@ -28,7 +28,7 @@ import Control.Monad.Reader (liftIO)
28import Data.Maybe (fromMaybe)
28import Data.Maybe (fromMaybe)
29import qualified Data.Map as M
29import qualified Data.Map as M
30
30
31−import Text.Hakyll.Context (ContextManipulation, renderDate)
31+import Text.Hakyll.Context (renderDate)
32import Text.Hakyll.Hakyll (Hakyll, Context)
32import Text.Hakyll.Hakyll (Hakyll, Context)
33import Text.Hakyll.Render (render, renderChain)
33import Text.Hakyll.Render (render, renderChain)
34import Text.Hakyll.Renderables (createListing)
34import Text.Hakyll.Renderables (createListing)
src/Text/Hakyll/Internal/Render.hsdeleted−39
@@ -1,39 +0,0 @@
1−-- | Internal module do some low-level rendering.
2−module Text.Hakyll.Internal.Render
3− ( pureRender
4− , writePage
5− ) where
6−
7−import qualified Data.Map as M
8−import Control.Monad.Reader (liftIO)
9−import Data.Maybe (fromMaybe)
10−
11−import Text.Hakyll.File
12−import Text.Hakyll.Hakyll
13−import Text.Hakyll.HakyllAction
14−import Text.Hakyll.Internal.Template
15−
16−-- | A pure render function.
17−pureRender :: Template -- ^ Template to use for rendering.
18− -> Context -- ^ Renderable object to render with given template.
19− -> Context -- ^ The body of the result will contain the render.
20−pureRender template context =
21− -- Ignore $root when substituting here. We will only replace that in the
22− -- final render (just before writing).
23− let contextIgnoringRoot = M.insert "root" "$root" context
24− body = regularSubstitute template contextIgnoringRoot
25− in M.insert "body" body context
26−
27−-- | Write a page to the site destination. Final action after render
28−-- chains and such.
29−writePage :: HakyllAction Context ()
30−writePage = createHakyllAction $ \initialContext -> do
31− additionalContext' <- askHakyll getAdditionalContext
32− let url = fromMaybe (error "No url defined at write time.")
33− (M.lookup "url" initialContext)
34− body = fromMaybe "" (M.lookup "body" initialContext)
35− let context = additionalContext' `M.union` M.singleton "root" (toRoot url)
36− destination <- toDestination url
37− makeDirectories destination
38− -- Substitute $root here, just before writing.
39− liftIO $ writeFile destination $ finalSubstitute (fromString body) context
src/Text/Hakyll/Render.hs+27−3
@@ -14,12 +14,22 @@ import System.Directory (copyFile)
14import Data.Maybe (fromMaybe)
14import Data.Maybe (fromMaybe)
15import qualified Data.Map as M
15import qualified Data.Map as M
16
16
17−import Text.Hakyll.Hakyll (Hakyll, Context)
17+import Text.Hakyll.Hakyll (Hakyll, Context, askHakyll, getAdditionalContext)
18import Text.Hakyll.File
18import Text.Hakyll.File
19import Text.Hakyll.HakyllAction
19import Text.Hakyll.HakyllAction
20import Text.Hakyll.Internal.CompressCss
20import Text.Hakyll.Internal.CompressCss
21−import Text.Hakyll.Internal.Render
21+import Text.Hakyll.Internal.Template
22−import Text.Hakyll.Internal.Template (readTemplate)
22+
23+-- | A pure render function.
24+pureRender :: Template -- ^ Template to use for rendering.
25+ -> Context -- ^ Renderable object to render with given template.
26+ -> Context -- ^ The body of the result will contain the render.
27+pureRender template context =
28+ -- Ignore $root when substituting here. We will only replace that in the
29+ -- final render (just before writing).
30+ let contextIgnoringRoot = M.insert "root" "$root" context
31+ body = regularSubstitute template contextIgnoringRoot
32+ in M.insert "body" body context
23
33
24-- | Render to a Page.
34-- | Render to a Page.
25render :: FilePath -- ^ Template to use for rendering.
35render :: FilePath -- ^ Template to use for rendering.
@@ -101,3 +111,17 @@ css source = runHakyllActionIfNeeded css'
101 destination <- toDestination source
111 destination <- toDestination source
102 makeDirectories destination
112 makeDirectories destination
103 liftIO $ writeFile destination (compressCss contents)
113 liftIO $ writeFile destination (compressCss contents)
114+
115+-- | Write a page to the site destination. Final action after render
116+-- chains and such.
117+writePage :: HakyllAction Context ()
118+writePage = createHakyllAction $ \initialContext -> do
119+ additionalContext' <- askHakyll getAdditionalContext
120+ let url = fromMaybe (error "No url defined at write time.")
121+ (M.lookup "url" initialContext)
122+ body = fromMaybe "" (M.lookup "body" initialContext)
123+ let context = additionalContext' `M.union` M.singleton "root" (toRoot url)
124+ destination <- toDestination url
125+ makeDirectories destination
126+ -- Substitute $root here, just before writing.
127+ liftIO $ writeFile destination $ finalSubstitute (fromString body) context