on ef4c166 help sign in
hakyll/src/Text/Hakyll/CompressCSS.hs
29 lines 985 B history raw
1module Text.Hakyll.CompressCSS
2 ( compressCSS
3 ) where
5import Data.List
6import Text.Regex
8-- | Compress CSS to speed up your site.
9compressCSS :: String -> String
10compressCSS = compressSeparators
11 . compressWhitespace
12 . stripComments
14-- | Compresses certain forms of separators.
15compressSeparators :: String -> String
16compressSeparators str = subRegex (mkRegex "\\s*([;:])\\s*") str "\\1"
18-- | Compresses all whitespace.
19compressWhitespace :: String -> String
20compressWhitespace str = subRegex (mkRegex "\\s\\s*") str " "
22-- | Function that strips CSS comments away.
23stripComments :: String -> String
24stripComments [] = []
25stripComments str | isPrefixOf "/*" str = stripComments $ eatComments $ drop 2 str
26 | otherwise = (head str) : (stripComments $ tail str)
27 where eatComments str' | null str' = []
28 | isPrefixOf "*/" str' = drop 2 str'
29 | otherwise = eatComments $ tail str'