summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicole Rauch <nicole.rauch@me.com>2017-06-10 16:32:06 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2017-06-10 16:32:06 +0200
commit40945cd717b044d6d13c8b46050447d0fca61974 (patch)
tree34203ae2cbdfd7ff7198510ee947f38ea50bd567 /src
parentae6e241b9a65dd7df2c09ae769ba3eff7b182df9 (diff)
downloadhakyll-40945cd717b044d6d13c8b46050447d0fca61974.tar.gz
Some small CSS compression improvements
* We now also compress whitespace around commas. * Remove whitespace around some other operators as well. * Clarified the code around the separator compression and even improved the code (one case slipped through unnoticed).
Diffstat (limited to 'src')
-rw-r--r--src/Hakyll/Web/CompressCss.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Hakyll/Web/CompressCss.hs b/src/Hakyll/Web/CompressCss.hs
index 0371d8b..9f61534 100644
--- a/src/Hakyll/Web/CompressCss.hs
+++ b/src/Hakyll/Web/CompressCss.hs
@@ -33,14 +33,15 @@ compressCss = compressSeparators . stripComments . compressWhitespace
compressSeparators :: String -> String
compressSeparators [] = []
compressSeparators str
- | isConstant = head str : retainConstants compressSeparators (head str) (drop 1 str)
+ | isConstant = head str : retainConstants compressSeparators (head str) (drop 1 str)
| stripFirst = compressSeparators (drop 1 str)
| stripSecond = compressSeparators (head str : (drop 2 str))
| otherwise = head str : compressSeparators (drop 1 str)
where
isConstant = or $ map (isOfPrefix str) ["\"", "'"]
- stripFirst = or $ map (isOfPrefix str) [" ", " {", " }", " :", ";;", ";}"]
- stripSecond = or $ map (isOfPrefix str) ["{ ", "} ", ": ", "; "]
+ stripFirst = or $ map (isOfPrefix str) $ [";;", ";}"] ++ (map (\c -> " " ++ c) separators)
+ stripSecond = or $ map (isOfPrefix str) $ map (\c -> c ++ " ") separators
+ separators = [" ", "{", "}", ":", ";", ",", ">", "+", "!"]
--------------------------------------------------------------------------------
-- | Compresses all whitespace.
@@ -50,7 +51,7 @@ compressWhitespace str
| isConstant = head str : retainConstants compressWhitespace (head str) (drop 1 str)
| replaceOne = compressWhitespace (' ' : (drop 1 str))
| replaceTwo = compressWhitespace (' ' : (drop 2 str))
- | otherwise = head str : compressWhitespace (drop 1 str)
+ | otherwise = head str : compressWhitespace (drop 1 str)
where
isConstant = or $ map (isOfPrefix str) ["\"", "'"]
replaceOne = or $ map (isOfPrefix str) ["\t", "\n", "\r"]
@@ -61,9 +62,9 @@ compressWhitespace str
stripComments :: String -> String
stripComments [] = []
stripComments str
- | isConstant = head str : retainConstants stripComments (head str) (drop 1 str)
+ | isConstant = head str : retainConstants stripComments (head str) (drop 1 str)
| isPrefixOf "/*" str = stripComments $ eatComments $ drop 2 str
- | otherwise = head str : stripComments (drop 1 str)
+ | otherwise = head str : stripComments (drop 1 str)
where
isConstant = or $ map (isOfPrefix str) ["\"", "'"]
eatComments str'