diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-01-31 11:19:57 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-01-31 11:19:57 +0100 |
commit | 7afabf5c098efc2f0df482ab66d9091d7aa3bd23 (patch) | |
tree | a96a60459fa2d8fce6591d56d437d9da13c2b6fd /src/Text/Hakyll/Internal/CompressCss.hs | |
parent | 73d6b1d6614c3965afd96b710bfa79db94d2449e (diff) | |
download | hakyll-7afabf5c098efc2f0df482ab66d9091d7aa3bd23.tar.gz |
Better naming scheme.
Diffstat (limited to 'src/Text/Hakyll/Internal/CompressCss.hs')
-rw-r--r-- | src/Text/Hakyll/Internal/CompressCss.hs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Text/Hakyll/Internal/CompressCss.hs b/src/Text/Hakyll/Internal/CompressCss.hs new file mode 100644 index 0000000..4b19984 --- /dev/null +++ b/src/Text/Hakyll/Internal/CompressCss.hs @@ -0,0 +1,36 @@ +-- | Module used for CSS compression. The compression is currently in a simple +-- state, but would typically reduce the number of bytes by about 25%. +module Text.Hakyll.Internal.CompressCss + ( compressCss + ) where + +import Data.List (isPrefixOf) + +import Text.Hakyll.Regex (substituteRegex) + +-- | Compress CSS to speed up your site. +compressCss :: String -> String +compressCss = compressSeparators + . stripComments + . compressWhitespace + +-- | Compresses certain forms of separators. +compressSeparators :: String -> String +compressSeparators = substituteRegex "; *}" "}" + . substituteRegex " *([{};:]) *" "\\1" + . substituteRegex ";;*" ";" + +-- | Compresses all whitespace. +compressWhitespace :: String -> String +compressWhitespace = substituteRegex "[ \t\n][ \t\n]*" " " + +-- | Function that strips CSS comments away. +stripComments :: String -> String +stripComments [] = [] +stripComments str + | isPrefixOf "/*" str = stripComments $ eatComments $ drop 2 str + | otherwise = head str : stripComments (tail str) + where + eatComments str' | null str' = [] + | isPrefixOf "*/" str' = drop 2 str' + | otherwise = eatComments $ tail str' |