diff options
-rw-r--r-- | hakyll.cabal | 2 | ||||
-rw-r--r-- | src/Text/Hakyll/CompressCSS.hs | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/hakyll.cabal b/hakyll.cabal index 171c7ce..3312dc7 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -19,7 +19,7 @@ library ghc-options: -Wall hs-source-dirs: src/ build-depends: base >= 4 && < 5, template, filepath, directory, containers, bytestring, - pandoc >= 1 + pandoc >= 1, regex-compat exposed-modules: Text.Hakyll.Render Text.Hakyll.Renderable Text.Hakyll.Renderables diff --git a/src/Text/Hakyll/CompressCSS.hs b/src/Text/Hakyll/CompressCSS.hs index b638654..5cb3b16 100644 --- a/src/Text/Hakyll/CompressCSS.hs +++ b/src/Text/Hakyll/CompressCSS.hs @@ -3,10 +3,21 @@ module Text.Hakyll.CompressCSS ) where import Data.List +import Text.Regex -- | Compress CSS to speed up your site. compressCSS :: String -> String -compressCSS = stripComments +compressCSS = compressSeparators + . compressWhitespace + . stripComments + +-- | Compresses certain forms of separators. +compressSeparators :: String -> String +compressSeparators str = subRegex (mkRegex "\\s*([;:])\\s*") str "\\1" + +-- | Compresses all whitespace. +compressWhitespace :: String -> String +compressWhitespace str = subRegex (mkRegex "\\s\\s*") str " " -- | Function that strips CSS comments away. stripComments :: String -> String |