on master help sign in
Changed to a more general directory command, and added css command.
ef4c166Jasper Van der Jeugt
src/Text/Hakyll/File.hs+6−1
@@ -6,7 +6,8 @@ module Text.Hakyll.File
6 toURL,
6 toURL,
7 makeDirectories,
7 makeDirectories,
8 getRecursiveContents,
8 getRecursiveContents,
9− isCacheValid
9+ isCacheValid,
10+ directory
10 ) where
11 ) where
11
12
12import System.Directory
13import System.Directory
@@ -46,6 +47,10 @@ getRecursiveContents topdir = do
46 return (concat paths)
47 return (concat paths)
47 where isProper = not . (== '.') . head
48 where isProper = not . (== '.') . head
48
49
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+
49-- | Check is a cache file is still valid.
54-- | Check is a cache file is still valid.
50isCacheValid :: FilePath -> [FilePath] -> IO Bool
55isCacheValid :: FilePath -> [FilePath] -> IO Bool
51isCacheValid cache depends = doesFileExist cache >>= \exists ->
56isCacheValid cache depends = doesFileExist cache >>= \exists ->
src/Text/Hakyll/Render.hs+9−5
@@ -4,7 +4,7 @@ module Text.Hakyll.Render
4 renderAndConcat,
4 renderAndConcat,
5 renderChain,
5 renderChain,
6 static,
6 static,
7− staticDirectory
7+ css
8 ) where
8 ) where
9
9
10import Text.Template hiding (render)
10import Text.Template hiding (render)
@@ -18,6 +18,7 @@ import System.IO
18import Text.Hakyll.Page
18import Text.Hakyll.Page
19import Text.Hakyll.Renderable
19import Text.Hakyll.Renderable
20import Text.Hakyll.File
20import Text.Hakyll.File
21+import Text.Hakyll.CompressCSS
21
22
22-- | Execute an IO action only when the cache is invalid.
23-- | Execute an IO action only when the cache is invalid.
23depends :: FilePath -- ^ File to be rendered or created.
24depends :: FilePath -- ^ File to be rendered or created.
@@ -68,7 +69,10 @@ static source = depends destination [source]
68 (makeDirectories destination >> copyFile source destination)
69 (makeDirectories destination >> copyFile source destination)
69 where destination = toDestination source
70 where destination = toDestination source
70
71
71−-- | Mark a whole directory as static.
72+-- | Render a css file, compressing it.
72−staticDirectory :: FilePath -> IO ()
73+css :: FilePath -> IO ()
73−staticDirectory dir =
74+css source = depends destination [source] css'
74− getRecursiveContents dir >>= mapM_ static
75+ where destination = toDestination source
76+ css' = do h <- openFile source ReadMode
77+ contents <- hGetContents h
78+ writeFile destination (compressCSS contents)