summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/CompressCss.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2017-06-19 11:57:23 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2017-06-19 11:57:23 +0200
commit67ecff7ad383640bc73d64edc2506c7cc648a134 (patch)
tree6d328e43c3ab86c29a2d775fabaa23618c16fb51 /src/Hakyll/Web/CompressCss.hs
parent2df3209bafa08e6b77ee4a8598fc503269513527 (diff)
downloadhakyll-67ecff7ad383640bc73d64edc2506c7cc648a134.tar.gz
Move src/ to lib/, put Init.hs in src/
Diffstat (limited to 'src/Hakyll/Web/CompressCss.hs')
-rw-r--r--src/Hakyll/Web/CompressCss.hs86
1 files changed, 0 insertions, 86 deletions
diff --git a/src/Hakyll/Web/CompressCss.hs b/src/Hakyll/Web/CompressCss.hs
deleted file mode 100644
index 9f61534..0000000
--- a/src/Hakyll/Web/CompressCss.hs
+++ /dev/null
@@ -1,86 +0,0 @@
---------------------------------------------------------------------------------
--- | 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 Hakyll.Web.CompressCss
- ( compressCssCompiler
- , compressCss
- ) where
-
-
---------------------------------------------------------------------------------
-import Data.List (isPrefixOf)
-
-
---------------------------------------------------------------------------------
-import Hakyll.Core.Compiler
-import Hakyll.Core.Item
-
-
---------------------------------------------------------------------------------
--- | Compiler form of 'compressCss'
-compressCssCompiler :: Compiler (Item String)
-compressCssCompiler = fmap compressCss <$> getResourceString
-
-
---------------------------------------------------------------------------------
--- | Compress CSS to speed up your site.
-compressCss :: String -> String
-compressCss = compressSeparators . stripComments . compressWhitespace
-
-
---------------------------------------------------------------------------------
--- | Compresses certain forms of separators.
-compressSeparators :: String -> String
-compressSeparators [] = []
-compressSeparators 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) $ [";;", ";}"] ++ (map (\c -> " " ++ c) separators)
- stripSecond = or $ map (isOfPrefix str) $ map (\c -> c ++ " ") separators
- separators = [" ", "{", "}", ":", ";", ",", ">", "+", "!"]
-
---------------------------------------------------------------------------------
--- | Compresses all whitespace.
-compressWhitespace :: String -> String
-compressWhitespace [] = []
-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)
- where
- isConstant = or $ map (isOfPrefix str) ["\"", "'"]
- replaceOne = or $ map (isOfPrefix str) ["\t", "\n", "\r"]
- replaceTwo = or $ map (isOfPrefix str) [" \t", " \n", " \r", " "]
-
---------------------------------------------------------------------------------
--- | Function that strips CSS comments away.
-stripComments :: String -> String
-stripComments [] = []
-stripComments 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)
- where
- isConstant = or $ map (isOfPrefix str) ["\"", "'"]
- eatComments str'
- | null str' = []
- | isPrefixOf "*/" str' = drop 2 str'
- | otherwise = eatComments $ drop 1 str'
-
---------------------------------------------------------------------------------
--- | Helper function to handle string constants correctly.
-retainConstants :: (String -> String) -> Char -> String -> String
-retainConstants f delim str
- | null str = []
- | isPrefixOf [delim] str = head str : f (drop 1 str)
- | otherwise = head str : retainConstants f delim (drop 1 str)
-
---------------------------------------------------------------------------------
--- | Helper function to determine whether a string is a substring.
-isOfPrefix :: String -> String -> Bool
-isOfPrefix = flip isPrefixOf