on master help sign in
Changed to a more general directory command, and added css command.
commitef4c166a1c1c918f47ee46933beb02e3edb8569d authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 18 Dec 2009, 19:38 (17 years ago) parentc1d93eb
2 files changed+15−6
src/Text/Hakyll/File.hs+6−1 src/Text/Hakyll/Render.hs+9−5
src/Text/Hakyll/File.hs+6−1
@@ -6,7 +6,8 @@ module Text.Hakyll.File
66 toURL,
77 makeDirectories,
88 getRecursiveContents,
9− isCacheValid
9+ isCacheValid,
10+ directory
1011 ) where
1112
1213import System.Directory
@@ -46,6 +47,10 @@ getRecursiveContents topdir = do
4647 return (concat paths)
4748 where isProper = not . (== '.') . head
4849
50+-- | Perform an IO action on every file in a given directory.
51+directory :: (FilePath -> IO ()) -> FilePath -> IO ()
52+directory action dir = getRecursiveContents dir >>= mapM_ action
53+
4954-- | Check is a cache file is still valid.
5055isCacheValid :: FilePath -> [FilePath] -> IO Bool
5156isCacheValid cache depends = doesFileExist cache >>= \exists ->
src/Text/Hakyll/Render.hs+9−5
@@ -4,7 +4,7 @@ module Text.Hakyll.Render
44 renderAndConcat,
55 renderChain,
66 static,
7− staticDirectory
7+ css
88 ) where
99
1010import Text.Template hiding (render)
@@ -18,6 +18,7 @@ import System.IO
1818import Text.Hakyll.Page
1919import Text.Hakyll.Renderable
2020import Text.Hakyll.File
21+import Text.Hakyll.CompressCSS
2122
2223-- | Execute an IO action only when the cache is invalid.
2324depends :: FilePath -- ^ File to be rendered or created.
@@ -68,7 +69,10 @@ static source = depends destination [source]
6869 (makeDirectories destination >> copyFile source destination)
6970 where destination = toDestination source
7071
71−-- | Mark a whole directory as static.
72−staticDirectory :: FilePath -> IO ()
73−staticDirectory dir =
74− getRecursiveContents dir >>= mapM_ static
72+-- | Render a css file, compressing it.
73+css :: FilePath -> IO ()
74+css source = depends destination [source] css'
75+ where destination = toDestination source
76+ css' = do h <- openFile source ReadMode
77+ contents <- hGetContents h
78+ writeFile destination (compressCSS contents)