on master help sign in
Simplified css and static code.
commit664111c00178039c5a68f62da7612fb04b25927c authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 5 Mar 2010, 12:22 (17 years ago) parentcd51ba5
3 files changed+32−37
src/Text/Hakyll/Internal/Render.hs+1−4 src/Text/Hakyll/Render.hs+6−30 src/Text/Hakyll/RenderAction.hs+25−3
src/Text/Hakyll/Internal/Render.hs+1−4
@@ -10,7 +10,6 @@ module Text.Hakyll.Internal.Render
1010import qualified Data.Map as M
1111import Control.Monad.Reader (liftIO)
1212import Data.Maybe (fromMaybe)
13−import System.IO (hPutStrLn, stderr)
1413
1514import Text.Hakyll.Context (Context, ContextManipulation)
1615import Text.Hakyll.File
@@ -42,6 +41,4 @@ writePage = createRenderAction $ \initialContext -> do
4241 destination <- toDestination url
4342 makeDirectories destination
4443    -- Substitute $root here, just before writing.
45− liftIO $ do
46− writeFile destination $ finalSubstitute (fromString body) context
47− hPutStrLn stderr $ "Writing " ++ destination
44+ liftIO $ writeFile destination $ finalSubstitute (fromString body) context
src/Text/Hakyll/Render.hs+6−30
@@ -1,8 +1,7 @@
11-- | Module containing rendering functions. All these functions are used to
22-- render files to the @_site@ directory.
33module Text.Hakyll.Render
4− ( depends
5− , render
4+ ( render
65 , renderWith
76 , renderAndConcat
87 , renderAndConcatWith
@@ -12,7 +11,6 @@ module Text.Hakyll.Render
1211 , css
1312 ) where
1413
15−import Control.Monad (unless)
1614import Control.Arrow ((>>>))
1715import Control.Monad.Reader (liftIO)
1816import System.Directory (copyFile)
@@ -27,16 +25,6 @@ import Text.Hakyll.Internal.CompressCss
2725import Text.Hakyll.Internal.Render
2826import Text.Hakyll.Internal.Template (readTemplate)
2927
30−-- | Execute an IO action only when the cache is invalid.
31−depends :: FilePath -- ^ File to be rendered or created.
32− -> [FilePath] -- ^ Files the render depends on.
33− -> Hakyll () -- ^ Action to execute when the file is out of date.
34− -> Hakyll ()
35−depends file dependencies action = do
36− destination <- toDestination file
37− valid <- isFileMoreRecent destination dependencies
38− unless valid action
39−
4028-- | Render to a Page.
4129render :: FilePath -- ^ Template to use for rendering.
4230 -> RenderAction Context Context -- ^ The render computation.
@@ -113,7 +101,7 @@ renderChainWith :: ContextManipulation
113101 -> RenderAction () Context
114102 -> Hakyll ()
115103renderChainWith manipulation templatePaths initial =
116− runRenderAction renderChainWith'
104+ runRenderActionIfNeeded renderChainWith'
117105 where
118106 renderChainWith' :: RenderAction () ()
119107 renderChainWith' = initial >>> manipulationAction >>> chain' >>> writePage
@@ -125,30 +113,18 @@ renderChainWith manipulation templatePaths initial =
125113-- | Mark a certain file as static, so it will just be copied when the site is
126114-- generated.
127115static :: FilePath -> Hakyll ()
128−static source = runRenderAction static'
116+static source = runRenderActionIfNeeded static'
129117 where
130− static' = RenderAction
131− { actionDependencies = [source]
132− , actionUrl = Just $ return source
133− , actionFunction = actionFunction'
134− }
135−
136− actionFunction' _ = do
118+ static' = createFileRenderAction source $ do
137119 destination <- toDestination source
138120 makeDirectories destination
139121 liftIO $ copyFile source destination
140122
141123-- | Render a css file, compressing it.
142124css :: FilePath -> Hakyll ()
143−css source = runRenderAction css'
125+css source = runRenderActionIfNeeded css'
144126 where
145− css' = RenderAction
146− { actionDependencies = [source]
147− , actionUrl = Just $ return source
148− , actionFunction = actionFunction'
149− }
150−
151− actionFunction' _ = do
127+ css' = createFileRenderAction source $ do
152128 contents <- liftIO $ readFile source
153129 destination <- toDestination source
154130 makeDirectories destination
src/Text/Hakyll/RenderAction.hs+25−3
@@ -2,17 +2,22 @@ module Text.Hakyll.RenderAction
22 ( RenderAction (..)
33 , createRenderAction
44 , createSimpleRenderAction
5+ , createFileRenderAction
56 , createManipulationAction
67 , chain
78 , runRenderAction
9+ , runRenderActionIfNeeded
810 ) where
911
10−import Prelude hiding ((.), id)
1112import Control.Category
12−import Control.Monad ((<=<), mplus)
13+import Control.Monad ((<=<), mplus, unless)
14+import Control.Monad.Reader (liftIO)
15+import Prelude hiding ((.), id)
16+import System.IO (hPutStrLn, stderr)
1317
14−import Text.Hakyll.Hakyll
1518import Text.Hakyll.Context
19+import Text.Hakyll.File (toDestination, isFileMoreRecent)
20+import Text.Hakyll.Hakyll
1621
1722data RenderAction a b = RenderAction
1823 { actionDependencies :: [FilePath]
@@ -26,6 +31,13 @@ createRenderAction f = id { actionFunction = f }
2631createSimpleRenderAction :: Hakyll b -> RenderAction () b
2732createSimpleRenderAction = createRenderAction . const
2833
34+createFileRenderAction :: FilePath -> Hakyll b -> RenderAction () b
35+createFileRenderAction path action = RenderAction
36+ { actionDependencies = [path]
37+ , actionUrl = Just $ return path
38+ , actionFunction = const action
39+ }
40+
2941instance Category RenderAction where
3042 id = RenderAction
3143 { actionDependencies = []
@@ -47,3 +59,13 @@ chain = foldl1 (>>>)
4759
4860runRenderAction :: RenderAction () a -> Hakyll a
4961runRenderAction action = actionFunction action ()
62+
63+runRenderActionIfNeeded :: RenderAction () () -> Hakyll ()
64+runRenderActionIfNeeded action = do
65+ url <- case actionUrl action of
66+ (Just u) -> u
67+ Nothing -> error "No url when checking dependencies."
68+ destination <- toDestination url
69+ valid <- isFileMoreRecent destination $ actionDependencies action
70+ unless valid $ do liftIO $ hPutStrLn stderr $ "Rendering " ++ destination
71+ runRenderAction action