summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-18 19:38:25 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2009-12-18 19:38:25 +0100
commitef4c166a1c1c918f47ee46933beb02e3edb8569d (patch)
tree14f25b8a0c5698bac5416f67ec61a459758fe95f /src
parentc1d93ebabfc03cf68ffabc7c2957c2c8935e4bc4 (diff)
downloadhakyll-ef4c166a1c1c918f47ee46933beb02e3edb8569d.tar.gz
Changed to a more general directory command, and added css command.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Hakyll/File.hs7
-rw-r--r--src/Text/Hakyll/Render.hs14
2 files changed, 15 insertions, 6 deletions
diff --git a/src/Text/Hakyll/File.hs b/src/Text/Hakyll/File.hs
index 07464ac..5bca261 100644
--- a/src/Text/Hakyll/File.hs
+++ b/src/Text/Hakyll/File.hs
@@ -6,7 +6,8 @@ module Text.Hakyll.File
toURL,
makeDirectories,
getRecursiveContents,
- isCacheValid
+ isCacheValid,
+ directory
) where
import System.Directory
@@ -46,6 +47,10 @@ getRecursiveContents topdir = do
return (concat paths)
where isProper = not . (== '.') . head
+-- | Perform an IO action on every file in a given directory.
+directory :: (FilePath -> IO ()) -> FilePath -> IO ()
+directory action dir = getRecursiveContents dir >>= mapM_ action
+
-- | Check is a cache file is still valid.
isCacheValid :: FilePath -> [FilePath] -> IO Bool
isCacheValid cache depends = doesFileExist cache >>= \exists ->
diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs
index 87467f7..7e9d55c 100644
--- a/src/Text/Hakyll/Render.hs
+++ b/src/Text/Hakyll/Render.hs
@@ -4,7 +4,7 @@ module Text.Hakyll.Render
renderAndConcat,
renderChain,
static,
- staticDirectory
+ css
) where
import Text.Template hiding (render)
@@ -18,6 +18,7 @@ import System.IO
import Text.Hakyll.Page
import Text.Hakyll.Renderable
import Text.Hakyll.File
+import Text.Hakyll.CompressCSS
-- | Execute an IO action only when the cache is invalid.
depends :: FilePath -- ^ File to be rendered or created.
@@ -68,7 +69,10 @@ static source = depends destination [source]
(makeDirectories destination >> copyFile source destination)
where destination = toDestination source
--- | Mark a whole directory as static.
-staticDirectory :: FilePath -> IO ()
-staticDirectory dir =
- getRecursiveContents dir >>= mapM_ static
+-- | Render a css file, compressing it.
+css :: FilePath -> IO ()
+css source = depends destination [source] css'
+ where destination = toDestination source
+ css' = do h <- openFile source ReadMode
+ contents <- hGetContents h
+ writeFile destination (compressCSS contents)